package com.qili.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qili.core.utils.DictTypes;
import com.qili.core.utils.DictUtil;
import com.qili.entity.base.BaseCompanyOwner;
import com.qili.entity.base.BaseDict;
import com.qili.entity.jc.*;
import com.qili.entity.jc.dto.JcPayRecordDTO;
import com.qili.entity.jc.dto.JcProjectDTO;
import com.qili.entity.jc.dto.JcProjectPayDTO;
import com.qili.entity.supervisor.*;
import com.qili.entity.supervisor.dto.SupervisorPayRecordDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectFromsDTO;
import com.qili.entity.supervisor.dto.SupervisorProjectPayDTO;
import com.qili.entity.supplier.OaData;
import com.qili.entity.supplier.dto.OaReDataDTO;
import com.qili.entity.sys.SysRegion;
import com.qili.entity.sys.SysUser;
import com.qili.entity.sys.dto.SysUserDTO;
import com.qili.entity.zx.*;
import com.qili.entity.zx.dto.ZxPayRecordDTO;
import com.qili.entity.zx.dto.ZxProjectDTO;
import com.qili.entity.zx.dto.ZxProjectPayDTO;
import com.qili.mapper.sys.SysUserMapper;
import com.qili.service.SysUserService;
import com.qili.service.base.BaseCompanyOwnerService;
import com.qili.service.base.BaseMilepostService;
import com.qili.service.base.SupervisorProjectMilepostService;
import com.qili.service.base.SupervisorProjectStageService;
import com.qili.service.jc.*;
import com.qili.service.supervisor.SupervisorFileTempService;
import com.qili.service.supervisor.SupervisorPayRecordService;
import com.qili.service.supervisor.SupervisorProjectPayService;
import com.qili.service.supervisor.SupervisorProjectService;
import com.qili.service.supplier.OaDataService;
import com.qili.service.supplier.SupplierProjectManagerService;
import com.qili.service.sys.SysRegionService;
import com.qili.service.zx.*;
import com.qili.util.*;
import io.swagger.annotations.ApiOperation;
import net.sf.jxls.transformer.XLSTransformer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zhaoyongke
 * @date 2021/5/10
 * @description
 */
@RequestMapping("/search/buProjectInfo")
@Controller
public class BuProjectInfoController {
    @Autowired
    BaseCompanyOwnerService baseCompanyOwnerService;
    @Autowired
    OaDataService oaDataService;
    @Autowired
    SysUserMapper sysUserMapper;
    @Autowired
    SysRegionService sysRegionService;
    @Autowired
    private SupervisorProjectService supervisorProjectService;
    @Autowired
    SupplierProjectManagerService supplierProjectManagerService;
    @Autowired
    SupervisorPayRecordService supervisorPayRecordService;
    @Autowired
    SupervisorFileTempService tempService;
    @Autowired
    UploadUtil uploadUtil;
    @Autowired
    SupervisorProjectPayService supervisorProjectPayService;
    @Autowired
    SupervisorProjectStageService supervisorProjectStageService;
    @Autowired
    BaseMilepostService baseMilepostService;
    @Autowired
    SupervisorProjectMilepostService supervisorProjectMilepostService;
    @Autowired
    ZxProjectService zxProjectService;
    @Autowired
    ZxPayRecordService zxPayRecordService;
    @Autowired
    JcProjectService jcProjectService;
    @Autowired
    JcPayRecordService jcPayRecordService;
    @Autowired
    ZxProjectPayService zxProjectPayService;
    @Autowired
    ZxProjectMilepostService zxProjectMilepostService;
    @Autowired
    ZxProjectStageService zxProjectStageService;
    @Autowired
    JcProjectPayService jcProjectPayService;
    @Autowired
    JcProjectMilepostService jcProjectMilepostService;
    @Autowired
    JcProjectStageService jcProjectStageService;
    @Autowired
    SysUserService userService;
    @Autowired
    SysUserService sysUserService;

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:监理项目统计
     * @Date:15:12 2021/5/10
     */
    @GetMapping("jlProTjIndex")
    @RequiresPermissions("zn:jc:ywxm:jl")
    public String showIndex(Model model) {
        // 项目归属
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("com", AlstCompany);
        //项目类型
        List<BaseDict> projectTypeList = DictUtil.getDictByType(DictTypes.PROJECT_TYPE);
        model.addAttribute("projectTypeList", projectTypeList);
        //行业
        List<BaseDict> AlstHyType = DictUtil.getDictByType(DictTypes.INDUSTRY);
        model.addAttribute("HyTypelist", AlstHyType);
        // 投资额区间
        List<BaseDict> tzelist = DictUtil.getDictByType(DictTypes.STZE001);
        model.addAttribute("tzelist", tzelist);

        // 项目进度q区间
        List<BaseDict> jdlist = DictUtil.getDictByType(DictTypes.SPJD001);
        model.addAttribute("jdlist", jdlist);
        //监理服务费
        List<BaseDict> JLFWFlist = DictUtil.getDictByType(DictTypes.JLFWF001);
        model.addAttribute("jlfwf", JLFWFlist);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("provincelist", provincelist);

        return "/decision/buProjectInfo/jlTjIndex";
    }
    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:咨询项目统计
     * @Date:15:12 2021/5/10
     */
    @GetMapping("zxProTjIndex")
    @RequiresPermissions("zn:jc:ywxm:zx")
    public String zxProTjIndex(Model model) {
        // 项目归属
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("com", AlstCompany);
        //项目类型
        List<BaseDict> projectTypeList = DictUtil.getDictByType(DictTypes.PROJECT_TYPEZX);
        model.addAttribute("projectTypeList", projectTypeList);
        //行业
        List<BaseDict> AlstHyType = DictUtil.getDictByType(DictTypes.INDUSTRY);
        model.addAttribute("HyTypelist", AlstHyType);
        // 投资额区间
        List<BaseDict> tzelist = DictUtil.getDictByType(DictTypes.STZE001);
        model.addAttribute("tzelist", tzelist);

        // 项目进度q区间
        List<BaseDict> jdlist = DictUtil.getDictByType(DictTypes.SPJD001);
        model.addAttribute("jdlist", jdlist);
        //监理服务费
        List<BaseDict> JLFWFlist = DictUtil.getDictByType(DictTypes.JLFWF001);
        model.addAttribute("jlfwf", JLFWFlist);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("provincelist", provincelist);

        return "/decision/buProjectInfo/zxProTj";
    }







    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:信息系统合同台账
     * @Date:15:12 2021/5/10
     */
    @GetMapping("oaDataTjIndex")
    @RequiresPermissions("zn:jc:ywxm:xxtz")
    public String oaDataTjIndex(Model model) {
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("provincelist", provincelist);
        return "/decision/buProjectInfo/OaDataIndex";
    }

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:合同信息统计
     * @Date:15:12 2021/5/10
     */
    @GetMapping("oaDataTj")
    @RequiresPermissions("zn:jc:ywxm:htxx")
    public String oaDataTj(Model model) {
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("provincelist", provincelist);
        return "/decision/buProjectInfo/OaDataTj";
    }
    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    @ApiOperation(value = "/showProjectJLTjList", httpMethod = "GET", notes = "展示监理统计信息")
    @GetMapping(value = "/showProjectJLTjList")
    @ResponseBody
    public ReType selectJLTjList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        Subject subject = SecurityUtils.getSubject();
        String tjType = dto.getTjType();
        if("day".equals(tjType)){

        }else if("week".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("~");
                dto.setStartWjDate(split[0]);
                dto.setEndWjDate(split[1]);
            }
        }else if("month".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(startdate+"-01");
                dto.setEndWjDate(startdate+"-31");
            }
        }else if("quarter".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("-");
                String year=split[0];
                String jd=split[1];
                if("1".equals(jd)){
                    dto.setStartWjDate(year+"-01-01");
                    dto.setEndWjDate(year+"-03-31");
                }else if("2".equals(jd)){
                    dto.setStartWjDate(year+"-04-01");
                    dto.setEndWjDate(year+"-06-30");
                }else if("3".equals(jd)){
                    dto.setStartWjDate(year+"-07-01");
                    dto.setEndWjDate(year+"-09-30");
                }else if("4".equals(jd)){
                    dto.setStartWjDate(year+"-10-01");
                    dto.setEndWjDate(year+"-12-31");
                }
            }
        }else if("year".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                dto.setEndWjDate(startdate+"-12-31");
            }
        }

        System.out.println(dto.getStartWjDate()+"开始时间========================");
        System.out.println(dto.getEndWjDate()+"结束时间========================");
        // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
        // 分公司总经理  看到自己公司的
        // 分公司工程部经理  只能看到自己的
        if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl")   ){
            // 分公司总经理  看到自己公司的
            SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
            // 公司Id
            String companyName = sysUser.getCompanyName();
            if(StringUtils.isBlank(companyName)){
                // 如果所所属公司为空  就不能显示出来信息
                dto.setUserId("5555");
            }else{
                dto.setProjectOwner(companyName);
            }
        }
        //已经结束状态
        ReType re = new ReType();
        dto.setDestatus("000");
        String tzMoney = dto.getTzMoney();
        dto.setField(humpToUnderline(dto.getField()));
        //处理投资额区间
        if (StringUtil.isNotBlank(tzMoney)) {
            String[] tzMoneystr = tzMoney.split(",");
            if (tzMoneystr.length == 2) {
                String minTzMoney = tzMoneystr[0];
                String maxTzMoney = tzMoneystr[1];
                dto.setMinTzMoney(minTzMoney);
                dto.setMaxTzMoney(maxTzMoney);
            }
        }
        //处理监理服务费区间
        // 汇款及时性
        // 是否延期
        String isYq = dto.getIsYq();
        Page<SupervisorProjectDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<SupervisorProjectDTO> data = supervisorProjectService.selectSupervisorJlTjProject(dto);
        return new ReType(tPage.getTotal(),data);

    }




    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    @ApiOperation(value = "/showProjectZxTjList", httpMethod = "GET", notes = "展示监理统计信息")
    @GetMapping(value = "/showProjectZxTjList")
    @ResponseBody
    public ReType showProjectZxTjList(ZxProjectDTO dto, Model model, String page, String limit) {
        Subject subject = SecurityUtils.getSubject();

        String tjType = dto.getTjType();
        if("day".equals(tjType)){

        }else if("week".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("~");
                dto.setStartWjDate(split[0]);
                dto.setEndWjDate(split[1]);
            }
        }else if("month".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(startdate+"-01");
                dto.setEndWjDate(startdate+"-31");
            }
        }else if("quarter".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("-");
                String year=split[0];
                String jd=split[1];
                if("1".equals(jd)){
                    dto.setStartWjDate(year+"-01-01");
                    dto.setEndWjDate(year+"-03-31");
                }else if("2".equals(jd)){
                    dto.setStartWjDate(year+"-04-01");
                    dto.setEndWjDate(year+"-06-30");
                }else if("3".equals(jd)){
                    dto.setStartWjDate(year+"-07-01");
                    dto.setEndWjDate(year+"-09-30");
                }else if("4".equals(jd)){
                    dto.setStartWjDate(year+"-10-01");
                    dto.setEndWjDate(year+"-12-31");
                }
            }
        }else if("year".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                dto.setEndWjDate(startdate+"-12-31");
            }
        }

        // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
        // 分公司总经理  看到自己公司的
        // 分公司工程部经理  只能看到自己的
        // 分公司咨询部门经理 只能看到自己的
        // 咨询部门经理   总部的
        if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl") ||  subject.hasRole("fgsdeptcheckpersonzx") ||  subject.hasRole("deptcheckpersonzx")    ){
            // 分公司总经理  看到自己公司的
            SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
            // 公司Id
            String companyName = sysUser.getCompanyName();
            if(StringUtils.isBlank(companyName)){
                // 如果所所属公司为空  就不能显示出来信息
                dto.setUserId("5555");
            }else{
                dto.setProjectOwner(companyName);
            }
        }
        //已经结束状态
        ReType re = new ReType();
        dto.setDestatus("000");
        String tzMoney = dto.getTzMoney();
        dto.setField(humpToUnderline(dto.getField()));
        //处理投资额区间
        if (StringUtil.isNotBlank(tzMoney)) {
            String[] tzMoneystr = tzMoney.split(",");
            if (tzMoneystr.length == 2) {
                String minTzMoney = tzMoneystr[0];
                String maxTzMoney = tzMoneystr[1];
                dto.setMinTzMoney(minTzMoney);
                dto.setMaxTzMoney(maxTzMoney);
            }
        }
        //处理监理服务费区间
        // 汇款及时性
        // 是否延期
        String isYq = dto.getIsYq();
        Page<ZxProjectDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<ZxProjectDTO> data = zxProjectService.selectZxJlTjProject(dto);
        return new ReType(tPage.getTotal(),data);

    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    @ApiOperation(value = "/showOaDataList", httpMethod = "GET", notes = "展示监理统计信息")
    @GetMapping(value = "/showOaDataList")
    @ResponseBody
    public ReType showOaDataList(OaReDataDTO dto, Model model, int page, int limit) {
        //已经结束状态
        ReType re = new ReType();
        if(!"".equals(dto.getSheng()) && dto.getSheng() != null){
            dto.setSheng(sysRegionService.selectRegionBycode(dto.getSheng()).getName().replace("省",""));
        }
        if(!"".equals(dto.getShi()) && dto.getShi() != null){
            dto.setShi(sysRegionService.selectRegionBycode(dto.getShi()).getName().replace("市",""));
        }
        if("北京城区".equals(dto.getShi())){
            dto.setShi("北京");
        }
        /*List<OaData> data1 = oaDataService.selectList(dto);
        PageHelper.startPage(page, limit);*/
        Page<OaData> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<OaData> data = oaDataService.selectList(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(tPage.getTotal());
        re.setData(data);
        return re;

    }
    /**
     * @param id
     * @param type
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:14:51 2021/5/11
     */
    @ApiOperation(value = "/queryPayMode", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/queryPayMode")
    @ResponseBody
    public ReType queryPayMode(String id, String type, String page, String limit) {
        Page<OaData> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        //已经结束状态
        ReType re = new ReType();
        List<JcPayRecordDTO> data = jcPayRecordService.queryPayModeBy(id,type);
        re.setPageNum(Long.valueOf(page));
        re.setCount(tPage.getTotal());
        re.setData(data);
        return re;

    }
    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    @ApiOperation(value = "/showOaDataListAll", httpMethod = "GET", notes = "展示监理统计信息")
    @GetMapping(value = "/showOaDataListAll")
    @ResponseBody
    public ReType showOaDataListAll(OaReDataDTO dto, Model model, int page, int limit) {
        Page<OaData> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        //已经结束状态
        ReType re = new ReType();
        List<OaReDataDTO> data = oaDataService.queryHtAll(dto);
        for (OaReDataDTO oaDto:
                data) {
            if("jl".equals(oaDto.getType())){
                SupervisorProject supervisorProject = supervisorProjectService.selectByPrimaryKey(oaDto.getId());
                SupervisorPayRecordDTO supervisorPayRecord = new SupervisorPayRecordDTO();
                supervisorPayRecord.setProjectId(oaDto.getId());
                List<SupervisorPayRecord> list = supervisorPayRecordService.select(supervisorPayRecord);
                if(list!=null){
                    oaDto.setJlfkqk("已还款");
                    oaDto.setJlhte(supervisorProject.getHtMoney());
                    BigDecimal zxbig = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        BigDecimal moneybig = new BigDecimal(list.get(i).getZfMoney());
                        zxbig = zxbig.add(moneybig);
                    }
                    oaDto.setJlyhkje(zxbig.toString());
                    if(!"".equals(supervisorProject.getHtMoney()) && supervisorProject.getHtMoney() != null){
                        BigDecimal bigDecimal = new BigDecimal(supervisorProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = zxbig.multiply(new BigDecimal(100));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setJlyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setJlfkqk("未还款");
                    oaDto.setJlhte(supervisorProject.getHtMoney());
                    oaDto.setJlyhkje("0");
                    oaDto.setJlyhkbl("0%");
                }
            }else if("zx".equals(oaDto.getType())){
                ZxProject zxProject = zxProjectService.selectByPrimaryKey(oaDto.getId());
                ZxPayRecordDTO zxPayRecord = new ZxPayRecordDTO();
                zxPayRecord.setProjectId(oaDto.getId());
                List<ZxPayRecord> list = zxPayRecordService.select(zxPayRecord);
                if(list!=null){
                    oaDto.setZxfkqk("已还款");
                    oaDto.setZxhte(zxProject.getHtMoney());
                    BigDecimal x = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        x = x.add(new BigDecimal(list.get(i).getZfMoney()));
                    }
                    oaDto.setZxyhkje(x+"");
                    if(!"".equals(zxProject.getHtMoney()) && zxProject.getHtMoney() != null){
                        BigDecimal bigDecimal = new BigDecimal(zxProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = x.multiply(new BigDecimal("100"));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setZxyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setZxfkqk("未还款");
                    oaDto.setZxhte(zxProject.getHtMoney());
                    oaDto.setZxyhkje("0");
                    oaDto.setZxyhkbl("0%");
                }
            }else if("jc".equals(oaDto.getType())){
                JcProject jcProject = jcProjectService.selectByPrimaryKey(oaDto.getId());
                JcPayRecordDTO jcPayRecord = new JcPayRecordDTO();
                jcPayRecord.setProjectId(oaDto.getId());
                List<JcPayRecord> list = jcPayRecordService.select(jcPayRecord);
                if(list!=null){
                    oaDto.setJcfkqk("已还款");
                    oaDto.setJchte(jcProject.getHtMoney());
                    BigDecimal x = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        x = x.add(new BigDecimal(list.get(i).getZfMoney()));
                    }
                    oaDto.setJcyhkje(x+"");
                    if(!"".equals(jcProject.getHtMoney()) && jcProject.getHtMoney() != null){
                        BigDecimal bigDecimal = new BigDecimal(jcProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = x.multiply(new BigDecimal("100"));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setJcyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setJcfkqk("未还款");
                    oaDto.setJchte(jcProject.getHtMoney());
                    oaDto.setJcyhkje("0");
                    oaDto.setJcyhkbl("0%");
                }
            }
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(tPage.getTotal());
        re.setData(data);
        return re;
    }
    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    public Map<String,List> showOaData(OaReDataDTO dto) {
        Map<String,List> map = new HashMap<>();
        List<JcPayRecordDTO> jcList = new ArrayList<>();
        List<JcPayRecordDTO> jlList = new ArrayList<>();
        List<JcPayRecordDTO> zxList = new ArrayList<>();
        List<OaReDataDTO> data = oaDataService.queryHtAll(dto);
        for (OaReDataDTO oaDto:
                data) {
            if("jl".equals(oaDto.getType())){
                List<JcPayRecordDTO> xList = jcPayRecordService.queryPayModeBy(oaDto.getId(),"监理");
                jlList.addAll(xList);
                SupervisorProject supervisorProject = supervisorProjectService.selectByPrimaryKey(oaDto.getId());
                SupervisorPayRecordDTO supervisorPayRecord = new SupervisorPayRecordDTO();
                supervisorPayRecord.setProjectId(oaDto.getId());
                List<SupervisorPayRecord> list = supervisorPayRecordService.select(supervisorPayRecord);
                if(list!=null){
                    oaDto.setJlfkqk("已还款");
                    oaDto.setJlhte(supervisorProject.getHtMoney());
                    BigDecimal x = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        x = x.add(new BigDecimal(list.get(i).getZfMoney()));
                    }
                    oaDto.setJlyhkje(x+"");
                    if(!("".equals(supervisorProject.getHtMoney())) && supervisorProject.getHtMoney() != null){
                        BigDecimal bigDecimal = new BigDecimal(supervisorProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = x.multiply(new BigDecimal("100"));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setJlyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setJlfkqk("未还款");
                    oaDto.setJlhte(supervisorProject.getHtMoney());
                    oaDto.setJlyhkje("0");
                    oaDto.setJlyhkbl("0%");
                }
            }else if("zx".equals(oaDto.getType())){
                List<JcPayRecordDTO> xList = jcPayRecordService.queryPayModeBy(oaDto.getId(),"咨询");
                zxList.addAll(xList);
                ZxProject zxProject = zxProjectService.selectByPrimaryKey(oaDto.getId());
                ZxPayRecordDTO zxPayRecord = new ZxPayRecordDTO();
                zxPayRecord.setProjectId(oaDto.getId());
                List<ZxPayRecord> list = zxPayRecordService.select(zxPayRecord);
                if(list!=null){
                    oaDto.setZxfkqk("已还款");
                    oaDto.setZxhte(zxProject.getHtMoney());
                    BigDecimal x = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        x = x.add(new BigDecimal(list.get(i).getZfMoney()));
                    }
                    oaDto.setZxyhkje(x+"");
                    if(!"".equals(zxProject.getHtMoney()) && zxProject.getHtMoney() != null){
                        BigDecimal bigDecimal = new BigDecimal(zxProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = x.multiply(new BigDecimal("100"));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setZxyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setZxfkqk("未还款");
                    oaDto.setZxhte(zxProject.getHtMoney());
                    oaDto.setZxyhkje("0");
                    oaDto.setZxyhkbl("0%");
                }
            }else if("jc".equals(oaDto.getType())){
                List<JcPayRecordDTO> xList = jcPayRecordService.queryPayModeBy(oaDto.getId(),"检测");
                jcList.addAll(xList);
                JcProject jcProject = jcProjectService.selectByPrimaryKey(oaDto.getId());
                JcPayRecordDTO jcPayRecord = new JcPayRecordDTO();
                jcPayRecord.setProjectId(oaDto.getId());
                List<JcPayRecord> list = jcPayRecordService.select(jcPayRecord);
                if(list!=null){
                    oaDto.setJcfkqk("已还款");
                    oaDto.setJchte(jcProject.getHtMoney());
                    BigDecimal x = new BigDecimal(0);
                    for(int i = 0;i<list.size();i++){
                        x = x.add(new BigDecimal(list.get(i).getZfMoney()));
                    }
                    oaDto.setJcyhkje(x+"");
                    if(StringUtils.isNotBlank(jcProject.getHtMoney())){
                        BigDecimal bigDecimal = new BigDecimal(jcProject.getHtMoney());
                        if(!(bigDecimal.equals(BigDecimal.ZERO))){
                            BigDecimal bigDecimal1 = x.multiply(new BigDecimal("100"));
                            BigDecimal bigDecimal2 = bigDecimal1.divide(bigDecimal, 2, BigDecimal.ROUND_HALF_UP);
                            String arrivalMoney = bigDecimal2.toString();
                            oaDto.setJcyhkbl(arrivalMoney+"%");
                        }
                    }
                }else{
                    oaDto.setJcfkqk("未还款");
                    oaDto.setJchte(jcProject.getHtMoney());
                    oaDto.setJcyhkje("0");
                    oaDto.setJcyhkbl("0%");
                }
            }
        }
        map.put("list4",jcList);
        map.put("list2",jlList);
        map.put("list3",zxList);
        map.put("list1",data);
        return map;
    }
    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:14:51 2021/5/11
     */
    @ApiOperation(value = "/selectYKfPList", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectYKfPList")
    @ResponseBody
    public ReType selectYKfPList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }



    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:14:51 2021/5/11
     */
    @ApiOperation(value = "/selectYKfPListZx", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectYKfPListZx")
    @ResponseBody
    public ReType selectYKfPListZx(ZxProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:已开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/viewYKfP")
    public String viewYKfP(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已开票金额共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYkFp";
    }
    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:已开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/viewYKfPZx")
    public String viewYKfPZx(ZxProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已开票金额共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYkFpZx";
    }





    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:未开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/noviewYKfP")
    public String noviewYKfP(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        // 已开发票金额
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        BigDecimal fpmoney = je;
        String htMoney = project.getHtMoney();
        BigDecimal htMoneyDe = new BigDecimal(htMoney);

        // 查询设置的回款节点
        SupervisorProjectPay pay = new SupervisorProjectPay();
        pay.setSppPrjid(projectId);
        List<SupervisorProjectPay> pays = supervisorProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        //   25  50  20  30
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if(StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        if (htMoneyDe.compareTo(je) == 1) {

            BigDecimal result2 = htMoneyDe.subtract(fpmoney);
            String jsfpstr = result2.stripTrailingZeros().toPlainString();
            String str = "未开票金额共" + num + "笔，共" + jsfpstr + "元";
            model.addAttribute("moneystr", str);
        }
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNoYkFp";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:未开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/noviewYKfPZx")
    public String noviewYKfPZx(ZxProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        // 已开发票金额
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        BigDecimal fpmoney = je;
        String htMoney = project.getHtMoney();
        BigDecimal htMoneyDe = new BigDecimal(htMoney);

        // 查询设置的回款节点
        ZxProjectPay pay = new ZxProjectPay();
        pay.setSppPrjid(projectId);
        List<ZxProjectPay> pays = zxProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        //   25  50  20  30
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if(StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        if (htMoneyDe.compareTo(je) == 1) {

            BigDecimal result2 = htMoneyDe.subtract(fpmoney);
            String jsfpstr = result2.stripTrailingZeros().toPlainString();
            String str = "未开票金额共" + num + "笔，共" + jsfpstr + "元";
            model.addAttribute("moneystr", str);
        }
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNoYkFpZx";
    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 查询未开发票金额
     * @Date:16:25 2021/5/28
     */
    @ApiOperation(value = "/selectNoKfPList", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectNoKfPList")
    @ResponseBody
    public ReType selectNoKfPList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }

        }
        // 查询设置的回款节点
        SupervisorProjectPay pay = new SupervisorProjectPay();
        pay.setSppPrjid(projectId);
        List<SupervisorProjectPay> pays = supervisorProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        List<SupervisorPayRecord> prs = new ArrayList<SupervisorPayRecord>();
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if(StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    BigDecimal result2 = addfpMoney.subtract(je);
                    SupervisorPayRecord dtomony = new SupervisorPayRecord();
                    dtomony.setFpMoney(result2.toString());
                    prs.add(dtomony);
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(prs.size());
        re.setData(prs);
        return re;

    }
    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 查询未开发票金额
     * @Date:16:25 2021/5/28
     */
    @ApiOperation(value = "/selectNoKfPListZx", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectNoKfPListZx")
    @ResponseBody
    public ReType selectNoKfPListZx(ZxProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if(StringUtil.isNotBlank(fpMoney)){
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }

        }
        // 查询设置的回款节点
        ZxProjectPay pay = new ZxProjectPay();
        pay.setSppPrjid(projectId);
        List<ZxProjectPay> pays = zxProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        List<ZxPayRecord> prs = new ArrayList<ZxPayRecord>();
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    BigDecimal result2 = addfpMoney.subtract(je);
                    ZxPayRecord dtomony = new ZxPayRecord();
                    dtomony.setFpMoney(result2.toString());
                    prs.add(dtomony);
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(prs.size());
        re.setData(prs);
        return re;

    }


    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:18:00 2021/5/28
     */
    @GetMapping(value = "/viewYhkje")
    public String viewYhkje(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addzfMoney = new BigDecimal(zfMoney);
                je = je.add(addzfMoney);
            }

        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已回款共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYhkje";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:18:00 2021/5/28
     */
    @GetMapping(value = "/viewYhkjeZx")
    public String viewYhkjeZx(ZxProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addzfMoney = new BigDecimal(zfMoney);
                je = je.add(addzfMoney);
            }

        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已回款共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYhkjeZx";
    }


    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 待回款金额
     * @Date:9:44 2021/5/29
     */
    @GetMapping(value = "/viewNohkje")
    public String viewNohkje(SupervisorProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        SupervisorProjectPayDTO payDTO = new SupervisorProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<SupervisorProjectPayDTO> supervisorProjectPayDTOS = supervisorProjectPayService.selectSupervisorProjectPay(payDTO);
        List<SupervisorProjectPayDTO> list = new ArrayList<>();
        int numno = 0;
        BigDecimal decimalno = new BigDecimal("0.0");
        for (int i = 0; i < supervisorProjectPayDTOS.size(); i++) {
            SupervisorProjectPayDTO payDTO1 = supervisorProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    numno++;
                    decimalno = decimalno.add(moneypay.subtract(paytotal));
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }

        }
        String jsfpstr = decimalno.stripTrailingZeros().toPlainString();
        String str = "未回款共" + numno + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNohkje";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 待回款金额
     * @Date:9:44 2021/5/29
     */
    @GetMapping(value = "/viewNohkjeZx")
    public String viewNohkjeZx(ZxProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        ZxProjectPayDTO payDTO = new ZxProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<ZxProjectPayDTO> zxProjectPayDTOS = zxProjectPayService.selectSupervisorProjectPay(payDTO);
        List<ZxProjectPayDTO> list = new ArrayList<>();
        int numno = 0;
        BigDecimal decimalno = new BigDecimal("0.0");
        for (int i = 0; i < zxProjectPayDTOS.size(); i++) {
            ZxProjectPayDTO payDTO1 = zxProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    numno++;
                    decimalno = decimalno.add(moneypay.subtract(paytotal));
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }

        }
        String jsfpstr = decimalno.stripTrailingZeros().toPlainString();
        String str = "未回款共" + numno + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNohkjeZx";
    }
    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 未回款金额
     * @Date:9:57 2021/5/29
     */
    @ApiOperation(value = "/selectNohkje", httpMethod = "GET", notes = "未回款金额")
    @GetMapping(value = "/selectNohkje")
    @ResponseBody
    public ReType selectNohkje(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<SupervisorPayRecordDTO> data = supervisorPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        SupervisorProjectPayDTO payDTO = new SupervisorProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<SupervisorProjectPayDTO> supervisorProjectPayDTOS = supervisorProjectPayService.selectSupervisorProjectPay(payDTO);
        List<SupervisorProjectPayDTO> list = new ArrayList<>();
        for (int i = 0; i < supervisorProjectPayDTOS.size(); i++) {
            SupervisorProjectPayDTO payDTO1 = supervisorProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }
            SupervisorProjectMilepost milepostnew = new SupervisorProjectMilepost();
            milepostnew.setMilepostNo(sppNo);
            milepostnew.setProjectId(dto.getProjectId());
            List<SupervisorProjectMilepost> milepostcurr = supervisorProjectMilepostService.select(milepostnew);
            // 阶段Id
            if (milepostcurr != null && milepostcurr.size() > 0) {
                String supervisorProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(supervisorProjectStageId);
                String payMiseNoDate = supervisorProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                supervisorProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
            }
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(list.size());
        re.setData(list);
        return re;

    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 未回款金额
     * @Date:9:57 2021/5/29
     */
    @ApiOperation(value = "/selectNohkjeZx", httpMethod = "GET", notes = "未回款金额")
    @GetMapping(value = "/selectNohkjeZx")
    @ResponseBody
    public ReType selectNohkjeZx(ZxProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<ZxPayRecordDTO> data = zxPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        ZxProjectPayDTO payDTO = new ZxProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<ZxProjectPayDTO> zxProjectPayDTOS = zxProjectPayService.selectSupervisorProjectPay(payDTO);
        List<ZxProjectPayDTO> list = new ArrayList<>();
        for (int i = 0; i < zxProjectPayDTOS.size(); i++) {
            ZxProjectPayDTO payDTO1 = zxProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }
            ZxProjectMilepost milepostnew = new ZxProjectMilepost();
            milepostnew.setMilepostNo(sppNo);
            milepostnew.setProjectId(dto.getProjectId());
            List<ZxProjectMilepost> milepostcurr = zxProjectMilepostService.select(milepostnew);
            // 阶段Id
            String zxProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
            ZxProjectStage stage = zxProjectStageService.selectByPrimaryKey(zxProjectStageId);
            String payMiseNoDate = zxProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
            zxProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(list.size());
        re.setData(list);
        return re;

    }


    /**
     * @param dtopro
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:17:59 2021/5/28
     */
    @ResponseBody
    @GetMapping(value = "/getlistYhkJe")
    public ReType getlistYhkJe(SupervisorProjectDTO dtopro) {
        ReType re = new ReType();
        try {
            List<SupervisorPayRecordDTO> AlistData = supervisorPayRecordService.selectPayRecordDe(dtopro);
            re.setCode(0);
            re.setData(AlistData);
        } catch (Exception e) {
            e.printStackTrace();
            re.setCode(500);
            re.setMsg("根据项目编号获取付款方式异常！！" + e.getMessage());
        }
        return re;
    }

    /**
     * @param dtopro
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:17:59 2021/5/28
     */
    @ResponseBody
    @GetMapping(value = "/getlistYhkJeZx")
    public ReType getlistYhkJeZx(ZxProjectDTO dtopro) {
        ReType re = new ReType();
        try {
            List<ZxPayRecordDTO> AlistData = zxPayRecordService.selectPayRecordDe(dtopro);
            re.setCode(0);
            re.setData(AlistData);
        } catch (Exception e) {
            e.printStackTrace();
            re.setCode(500);
            re.setMsg("根据项目编号获取付款方式异常！！" + e.getMessage());
        }
        return re;
    }


    // 项目完成率  index
    @GetMapping("/proFinishlvIndex")
    @RequiresPermissions("zn:jc:ywxm:xmwcl")
    public String proFinishlvIndex(Model model) {
        //项目类型
        List<BaseDict> ywList = DictUtil.getDictByType(DictTypes.YW_TYPE);
        model.addAttribute("projectTypeList", ywList);
        return "/decision/buProjectInfo/proFinishIndex";
    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:项目完成率
     * @Date:14:24 2021/5/14
     */
    @ApiOperation(value = "/proFinishlvList", httpMethod = "GET", notes = "项目完成率展示")
    @GetMapping(value = "/proFinishlvList")
    @ResponseBody
    public ReType proFinishlvList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        ReType re = new ReType();
        Subject subject = SecurityUtils.getSubject();
        // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
        // 分公司总经理  看到自己公司的
        if(subject.hasRole("fgszjl") || subject.hasRole("gcbjl") || subject.hasRole("fgsgcbjl") || subject.hasRole("fgsdeptcheckpersonjc") || subject.hasRole("deptcheckpersonjc") ||  subject.hasRole("fgsdeptcheckpersonzx") ||  subject.hasRole("deptcheckpersonzx") ){
            SysUser sysUser = userService.selectByPrimaryKey(CommonUtil.getUserId());
            // 公司Id
            String companyName = sysUser.getCompanyName();
            if(StringUtils.isBlank(companyName)){
                // 如果所所属公司为空  就不能显示出来信息
                dto.setUserId("5555");
            }else{
                dto.setProjectOwner(companyName);
            }
        }
        //监理类型
        List<SupervisorProjectDTO> data = supervisorProjectService.selectProFinishLv(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }
    //

    @GetMapping("/exportExcelPro")
    public void exportExcelPro(SupervisorProjectDTO dto, Model model, HttpServletResponse response) {
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<SupervisorProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = supervisorProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
                    List<SupervisorPayRecordDTO>   data1 = supervisorPayRecordService.selectPayRecord(dto);
                    List  dataEx=new ArrayList();
                    for (int i = 0; i <data1.size() ; i++) {
                        HashMap  mapdata=new HashMap();
                        mapdata.put("index",i+1);
                        mapdata.put("zfMoney",data1.get(i).getZfMoney());
                        mapdata.put("createDate",data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName =  project.getProjectName()+"项目已开发票金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName",project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    SupervisorProject project003 = supervisorProjectService.selectByPrimaryKey(projectId003);
                    List<SupervisorPayRecordDTO> data003 = supervisorPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    SupervisorProjectPay pay = new SupervisorProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<SupervisorProjectPay> pays = supervisorProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List dataEx003 = new ArrayList();
                    List<SupervisorPayRecord> prs = new ArrayList<SupervisorPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            SupervisorPayRecord dtomony = new SupervisorPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap  mapdata=new HashMap();
                            mapdata.put("index",i+1);
                            mapdata.put("zfMoney",result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName =  project003.getProjectName()+"项目未开发票金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName",project003.getProjectName());
                    ptid = "204";
                    break;
                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    SupervisorProject project004 = supervisorProjectService.selectByPrimaryKey(projectId004);
                    List<SupervisorPayRecordDTO> AlistData = supervisorPayRecordService.selectPayRecordDe(dto);
                    fileName =  project004.getProjectName()+"项目已回款金额"+DateUtil.getCurrentDateNoSpliter();
                    List  dataEx004=new ArrayList();

                    for (int i = 0; i <AlistData.size() ; i++) {
                        HashMap  mapdata=new HashMap();
                        mapdata.put("index",i+1);
                        mapdata.put("zfMoney",AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent",AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName",AlistData.get(i).getMilepostName());
                        mapdata.put("createDate",AlistData.get(i).getCreateDate());
                        String  status="";
                        if("001".equals(AlistData.get(i).getJsStatus())){
                            status="提前";
                        }else if("002".equals(AlistData.get(i).getJsStatus())){
                            status="按时";
                        }else if("003".equals(AlistData.get(i).getJsStatus())){
                            status="延期";
                        }
                        mapdata.put("jsStatus",status);
                        dataEx004.add(mapdata);
                    }
                    fileName =  project004.getProjectName()+"项目已回款金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx004);
                    map.put("projectName",project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    SupervisorProject project005 = supervisorProjectService.selectByPrimaryKey(projectId005);
                    List<SupervisorPayRecordDTO> data005 = supervisorPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal =jes;
                    SupervisorProjectPayDTO payDTO = new SupervisorProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<SupervisorProjectPayDTO> supervisorProjectPayDTOS = supervisorProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<SupervisorProjectPayDTO>  list=new ArrayList<>();
                    for (int i = 0; i < supervisorProjectPayDTOS.size(); i++) {
                        SupervisorProjectPayDTO payDTO1 = supervisorProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if(paytotal.compareTo(moneypay)<0){
                            if(paytotal.compareTo(new BigDecimal("0.0"))<0){
                                paytotal=new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal=paytotal.subtract(moneypay);

                        SupervisorProjectMilepost milepostnew = new SupervisorProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<SupervisorProjectMilepost> milepostcurr = supervisorProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String supervisorProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(supervisorProjectStageId);
                        String payMiseNoDate = supervisorProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        supervisorProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist=new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap  mapdata=new HashMap();
                        mapdata.put("index",i+1);
                        mapdata.put("zfMoney",list.get(i).getPayMoney());
                        mapdata.put("sppPersent",list.get(i).getSppPersent());
                        mapdata.put("milepostName",list.get(i).getMilepostName());
                        mapdata.put("createDate",list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName =  project005.getProjectName()+"项目未回款金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName",project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            ExcelExportUtil.exportExcel(response, map, fileName, ptid);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    /**
     * 预览表格
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/viewExcelPro")
    public JsonUtil viewExcelPro(SupervisorProjectDTO dto, Model model, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<SupervisorProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = supervisorProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    SupervisorProject project = supervisorProjectService.selectByPrimaryKey(projectId);
                    List<SupervisorPayRecordDTO>   data1 = supervisorPayRecordService.selectPayRecord(dto);
                    List  dataEx=new ArrayList();
                    for (int i = 0; i <data1.size() ; i++) {
                        HashMap  mapdata=new HashMap();
                        mapdata.put("index",i+1);
                        mapdata.put("zfMoney",data1.get(i).getZfMoney());
                        mapdata.put("createDate",data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName =  project.getProjectName()+"项目已开发票金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName",project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    SupervisorProject project003 = supervisorProjectService.selectByPrimaryKey(projectId003);
                    List<SupervisorPayRecordDTO> data003 = supervisorPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    SupervisorProjectPay pay = new SupervisorProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<SupervisorProjectPay> pays = supervisorProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List  dataEx003=new ArrayList();
                    List<SupervisorPayRecord> prs = new ArrayList<SupervisorPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            SupervisorPayRecord dtomony = new SupervisorPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap  mapdata=new HashMap();
                            mapdata.put("index",i+1);
                            mapdata.put("zfMoney",result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName =  project003.getProjectName()+"项目未开发票金额"+DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName",project003.getProjectName());
                    ptid = "204";
                    break;

                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    SupervisorProject project004 = supervisorProjectService.selectByPrimaryKey(projectId004);
                    List<SupervisorPayRecordDTO> AlistData = supervisorPayRecordService.selectPayRecordDe(dto);
                    fileName =  project004.getProjectName()+"项目已回款金额"+DateUtil.getCurrentDateNoSpliter();
                    List  dataEx004=new ArrayList();
                    for (int i = 0; i <AlistData.size() ; i++) {
                        HashMap  mapdata=new HashMap();
                        mapdata.put("index",i+1);
                        mapdata.put("zfMoney",AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent",AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName",AlistData.get(i).getMilepostName());
                        mapdata.put("createDate",AlistData.get(i).getCreateDate());
                        String  status="";
                        if("001".equals(AlistData.get(i).getJsStatus())){
                            status="提前";
                        }else if("002".equals(AlistData.get(i).getJsStatus())){
                            status="按时";
                        }else if("003".equals(AlistData.get(i).getJsStatus())){
                            status="延期";
                        }
                        mapdata.put("jsStatus",status);
                        dataEx004.add(mapdata);
                    }
                    map.put("records", dataEx004);
                    map.put("projectName",project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    SupervisorProject project005 = supervisorProjectService.selectByPrimaryKey(projectId005);
                    List<SupervisorPayRecordDTO> data005 = supervisorPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal =jes;
                    SupervisorProjectPayDTO payDTO = new SupervisorProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<SupervisorProjectPayDTO> supervisorProjectPayDTOS = supervisorProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<SupervisorProjectPayDTO>  list=new ArrayList<>();
                    for (int i = 0; i < supervisorProjectPayDTOS.size(); i++) {
                        SupervisorProjectPayDTO payDTO1 = supervisorProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if(paytotal.compareTo(moneypay)<0){
                            if(paytotal.compareTo(new BigDecimal("0.0"))<0){
                                paytotal=new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal = paytotal.subtract(moneypay);

                        SupervisorProjectMilepost milepostnew = new SupervisorProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<SupervisorProjectMilepost> milepostcurr = supervisorProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String supervisorProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        SupervisorProjectStage stage = supervisorProjectStageService.selectByPrimaryKey(supervisorProjectStageId);
                        String payMiseNoDate = supervisorProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        supervisorProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist=new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", list.get(i).getPayMoney());
                        mapdata.put("sppPersent", list.get(i).getSppPersent());
                        mapdata.put("milepostName", list.get(i).getMilepostName());
                        mapdata.put("createDate", list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName = project005.getProjectName() + "项目未回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName", project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            File formExcel = createFormExcel(ptid, fileName, map);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);

            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
        return result;
    }

    /**
     * 创建表单临时表格文件
     *
     * @param fileName
     * @param dataMap
     * @return
     */
    public File createFormExcel(String ptid, String fileName, HashMap dataMap) {
        try {
            // 获取模板信息
            String srcFilePath = FilePathUtil.getPathConfigTemplateFile(ptid);
            //生成的临时导出文件
            File destFile = File.createTempFile(fileName, ".xls");
            //  开始转换。利用  transformer 转到Excel
            XLSTransformer transformer = new XLSTransformer();
            // 参数：srcFilePath：模板源文件    cMap：需要导出的数据   destFile.getAbsolutePath()：下载的目标文件
            transformer.transformXLS(srcFilePath, dataMap, destFile.getAbsolutePath());
            return destFile;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InvalidFormatException e) {
            e.printStackTrace();
        }
        return null;
    }

    //=====================================================================产品分析=================================================

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description: 产品分析
     * @Date:10:46 2021/5/12
     */
    @GetMapping("cpfxIndex")
    @RequiresPermissions("zn:jc:cpfx")
    public String cpfxIndex(Model model) {
        return "/decision/cpfx/cpfx_index";
    }

    @GetMapping("cpfxDetail")
    public String cpfxDetail(SupervisorProjectDTO dto, Model model) {
        //品牌
        String modelName = dto.getModelName();
        //产品名称
        String cpName = dto.getCpName();
        model.addAttribute("modelName", modelName);
        model.addAttribute("cpName", cpName);
        return "/decision/cpfx/viewDetail";
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 产品分析列表
     * @Date:11:17 2021/5/12
     */
    @ApiOperation(value = "/cpfxList", httpMethod = "GET", notes = "产品分析")
    @GetMapping(value = "/cpfxList")
    @ResponseBody
    public Map<String, Object> cpfxList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
//        List<SupervisorProjectDTO> data = supervisorProjectService.selectCpFx(dto);
//        re.setPageNum(Long.valueOf(page));
//        re.setCount(data.size());
//        re.setData(data);
        List<SupervisorProjectDTO> data1 = supervisorProjectService.selectCpFx(dto);
        BigDecimal x = new BigDecimal(0);
        Page<SupervisorProjectDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<SupervisorProjectDTO> data = supervisorProjectService.selectCpFx(dto);
        for (int i = 0; i < data1.size(); i++) {
            SupervisorProjectDTO supervisorProjectDTO = data1.get(i);
            if (isNumeric(supervisorProjectDTO.getNum())) {
                x = x.add(new BigDecimal(supervisorProjectDTO.getNum()));
            }
        }
        if (!(x.equals(BigDecimal.ZERO))) {
            for (SupervisorProjectDTO supervisorProjectDTO : data
            ) {
                if (isNumeric(supervisorProjectDTO.getNum())) {
                    BigDecimal num = new BigDecimal(supervisorProjectDTO.getNum());
                    BigDecimal big1 = num.multiply(new BigDecimal("100"));
                    BigDecimal big = big1.divide(x, 2, BigDecimal.ROUND_HALF_UP);
                    supervisorProjectDTO.setPpzb(big + "%");
                }
                supervisorProjectDTO.setUserId(String.valueOf(x));
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("count", tPage.getTotal());
        map.put("data", data);
        int num = 0;
//        double ppzb = 0.00;
        BigDecimal ppzb = new BigDecimal(0.00);
        int proNum = 0;
        int jsNum = 0;
        for (SupervisorProjectDTO datum : data) {
            if(StringUtil.isNotBlank(datum.getNum())) {
                num += Integer.parseInt(datum.getNum());
            }
            proNum += Integer.parseInt(datum.getProNum());
            jsNum += Integer.parseInt(datum.getJsNum());
            if(StringUtil.isNotBlank(datum.getPpzb())) {
                ppzb = ppzb.add(new BigDecimal(datum.getPpzb().replace("%", "")));
            }
        }
        Map<String, Object> totalRow = new HashMap<>();
        totalRow.put("num", num);
        totalRow.put("ppzb", ppzb.toString() + "%");
        totalRow.put("proNum", proNum);
        totalRow.put("jsNum", jsNum);
        map.put("totalRow", totalRow);
        return map;
//        return new ReType(tPage.getTotal(), data);

    }

    /**
     * 利用正则表达式判断字符串是否是数字
     *
     * @param str
     * @return
     */
    public boolean isNumeric(String str) {
        if (str == null) {
            return false;
        }
        Pattern pattern = Pattern.compile("([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    /**
     * @param dto
     * @Author:zhaoyongke
     * @Description: 产品分析列表
     * @Date:11:17 2021/5/12
     */
    public List<SupervisorProjectDTO> cpfxList1(SupervisorProjectDTO dto) {
        //已经结束状态
        ReType re = new ReType();
        List<SupervisorProjectDTO> data = supervisorProjectService.selectCpFx(dto);

        for (int i = 0; i < data.size(); i++) {
            data.get(i).setXuhao(i + 1);
        }
        BigDecimal x = new BigDecimal(0);
        for (int i = 0; i < data.size(); i++) {
            SupervisorProjectDTO supervisorProjectDTO = data.get(i);
            if(StringUtils.isNotBlank(supervisorProjectDTO.getNum())){
                x = x.add(new BigDecimal(supervisorProjectDTO.getNum()));
            }
        }
        if (!(x.equals(BigDecimal.ZERO))) {
            for (SupervisorProjectDTO supervisorProjectDTO : data
            ) {

                //int num = Integer.parseInt(supervisorProjectDTO.getNum());
                if(StringUtils.isNotBlank(supervisorProjectDTO.getNum())) {
                    BigDecimal num = new BigDecimal(supervisorProjectDTO.getNum());
                    BigDecimal bai = new BigDecimal(100);
                    BigDecimal big1 = num.multiply(bai);
                    BigDecimal big = big1.divide(x, 2, BigDecimal.ROUND_HALF_UP);
                    supervisorProjectDTO.setPpzb(big + "%");
                }else{
                    supervisorProjectDTO.setPpzb(0.00 + "%");
                }
            }
        }
        return data;

    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 产品分析详情
     * @Date:11:18 2021/5/12
     */
    @ApiOperation(value = "/cpfxListDetail", httpMethod = "GET", notes = "产品分析")
    @GetMapping(value = "/cpfxListDetail")
    @ResponseBody
    public ReType cpfxListDetail(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        List<SupervisorProjectDTO> data = supervisorProjectService.selectCpFxDetail(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }

    /**
     * @param request
     * @Author:zhaoyongke
     * @Description:获取产品名称
     * @Date:14:46 2021/5/12
     */
    @GetMapping(value = "getCpName")
    @ResponseBody
    public JsonUtil getCpName(HttpServletRequest request) {
        JsonUtil re = new JsonUtil();
        try {
            SupervisorProjectDTO dto = new SupervisorProjectDTO();
            List<SupervisorProjectDTO> data = supervisorProjectService.selectCpName(dto);
            re.setFlag(true);
            re.setData(data);
            return re;
        } catch (Exception e) {
            e.printStackTrace();
            re.setFlag(false);
            re.setMsg("获取数据异常！！" + e.getMessage());
            return re;
        }
    }
    //=====================================================================产品分析=================================================


    // =========================start=========================================价格分析===========================start=============================

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:
     * @Date:13:42 2021/5/13
     */
    @GetMapping("jgfxIndex")
    @RequiresPermissions("zn:jc:jgfx")
    public String jgfxIndex(Model model) {
        return "/decision/jgfx/jgfx_index";
    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 价格分析
     * @Date:14:12 2021/5/13
     */
    @ApiOperation(value = "/jgfxList", httpMethod = "GET", notes = "价格分析")
    @GetMapping(value = "/jgfxList")
    @ResponseBody
    public ReType jgfxList(SupervisorProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        Page<SupervisorProjectDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<SupervisorProjectDTO> data = supervisorProjectService.selectJgFx(dto);
        for (int i = 0; i < data.size(); i++) {
            SupervisorProjectDTO dtoserch = new SupervisorProjectDTO();
            BeanUtil.copyNotNullBean(dto, dtoserch);

            String cpName = data.get(i).getCpName();
            String modelName = data.get(i).getModelName();
            String xhName = data.get(i).getXhName();
            dtoserch.setCpName(cpName);
            dtoserch.setModelName(modelName);
            dtoserch.setXhName(xhName);
            dtoserch.setMinNum(data.get(i).getMinNum());
            //===========================最低价开始===================================================================
            // 查询最高价 项目名称和 建设单位、
            List<SupervisorProjectDTO> supervisorProjectDTOS = supervisorProjectService.selectJgPro(dtoserch);
            List<SupervisorProjectDTO> supervisorProjectDTOJSdw = supervisorProjectService.selectJgJsDw(dtoserch);
            String projectNameMinStr = "";
            String jsNameMinStr = "";
            for (int j = 0; j < supervisorProjectDTOS.size(); j++) {
                if (supervisorProjectDTOS.get(j) != null) {
                    String projectName = supervisorProjectDTOS.get(j).getProjectName();
                    projectNameMinStr = projectNameMinStr + projectName + ",";
                }
            }
            for (int j = 0; j < supervisorProjectDTOJSdw.size(); j++) {
                if (supervisorProjectDTOJSdw.get(j) != null) {
                    String unitConstruction = supervisorProjectDTOJSdw.get(j).getUnitConstruction();
                    jsNameMinStr = jsNameMinStr + unitConstruction + ",";
                }
            }
            if (jsNameMinStr.length() > 0) {
                jsNameMinStr = jsNameMinStr.substring(0, jsNameMinStr.length() - 1);
            }
            if (projectNameMinStr.length() > 0) {
                projectNameMinStr = projectNameMinStr.substring(0, projectNameMinStr.length() - 1);
            }
            //===================================== 最低价end=========================================================
            data.get(i).setMinProjectName(projectNameMinStr);
            data.get(i).setMinJsName(jsNameMinStr);


            dtoserch.setMinNum("");
            dtoserch.setMaxNum(data.get(i).getMaxNum());
            String projectNameMaxStr = "";
            String jsNameMaxStr = "";
            List<SupervisorProjectDTO> supervisorProjectDTOSmax = supervisorProjectService.selectJgPro(dtoserch);
            List<SupervisorProjectDTO> supervisorProjectDTOJSdwMax = supervisorProjectService.selectJgJsDw(dtoserch);
            for (int j = 0; j < supervisorProjectDTOSmax.size(); j++) {
                if (supervisorProjectDTOSmax.get(j) != null) {
                    String projectName = supervisorProjectDTOSmax.get(j).getProjectName();
                    projectNameMaxStr = projectNameMaxStr + projectName + ",";
                }
            }
            for (int j = 0; j < supervisorProjectDTOJSdwMax.size(); j++) {
                if (supervisorProjectDTOJSdwMax.get(j) != null) {
                    String unitConstruction = supervisorProjectDTOJSdwMax.get(j).getUnitConstruction();
                    jsNameMaxStr = jsNameMaxStr + unitConstruction + ",";
                }
            }
            if (jsNameMinStr.length() > 0) {
                jsNameMaxStr = jsNameMaxStr.substring(0, jsNameMaxStr.length() - 1);
            }
            if (projectNameMinStr.length() > 0) {
                projectNameMaxStr = projectNameMaxStr.substring(0, projectNameMaxStr.length() - 1);
            }
            data.get(i).setMaxProjectName(projectNameMaxStr);
            data.get(i).setMaxJsName(jsNameMaxStr);

        }
        return new ReType(tPage.getTotal(), data);
    }

    public List<SupervisorProjectDTO> jgfxList2(SupervisorProjectDTO dto) {
        //已经结束状态
        ReType re = new ReType();
        List<SupervisorProjectDTO> data = supervisorProjectService.selectJgFx(dto);
        for (int i = 0; i < data.size(); i++) {
            SupervisorProjectDTO dtoserch = new SupervisorProjectDTO();
            BeanUtil.copyNotNullBean(dto, dtoserch);

            String cpName = data.get(i).getCpName();
            String modelName = data.get(i).getModelName();
            String xhName = data.get(i).getXhName();
            dtoserch.setCpName(cpName);
            dtoserch.setModelName(modelName);
            dtoserch.setXhName(xhName);
            dtoserch.setMinNum(data.get(i).getMinNum());
            //===========================最低价开始===================================================================
            // 查询最高价 项目名称和 建设单位、
            List<SupervisorProjectDTO> supervisorProjectDTOS = supervisorProjectService.selectJgPro(dtoserch);
            List<SupervisorProjectDTO> supervisorProjectDTOJSdw = supervisorProjectService.selectJgJsDw(dtoserch);
            String projectNameMinStr = "";
            String jsNameMinStr = "";
            for (int j = 0; j < supervisorProjectDTOS.size(); j++) {
                String projectName = supervisorProjectDTOS.get(j).getProjectName();
                projectNameMinStr = projectNameMinStr + projectName + ",";

            }
            for (int j = 0; j < supervisorProjectDTOJSdw.size(); j++) {
                String unitConstruction = supervisorProjectDTOJSdw.get(j).getUnitConstruction();
                jsNameMinStr = jsNameMinStr + unitConstruction + ",";

            }
            if (jsNameMinStr.length() > 0) {
                jsNameMinStr = jsNameMinStr.substring(0, jsNameMinStr.length() - 1);
            }
            if (projectNameMinStr.length() > 0) {
                projectNameMinStr = projectNameMinStr.substring(0, projectNameMinStr.length() - 1);
            }
            //===================================== 最低价end=========================================================
            data.get(i).setMinProjectName(projectNameMinStr);
            data.get(i).setMinJsName(jsNameMinStr);


            dtoserch.setMinNum("");
            dtoserch.setMaxNum(data.get(i).getMaxNum());
            String projectNameMaxStr = "";
            String jsNameMaxStr = "";
            List<SupervisorProjectDTO> supervisorProjectDTOSmax = supervisorProjectService.selectJgPro(dtoserch);
            List<SupervisorProjectDTO> supervisorProjectDTOJSdwMax = supervisorProjectService.selectJgJsDw(dtoserch);

            for (int j = 0; j < supervisorProjectDTOSmax.size(); j++) {
                String projectName = supervisorProjectDTOSmax.get(j).getProjectName();
                projectNameMaxStr = projectNameMaxStr + projectName + ",";
            }
            for (int j = 0; j < supervisorProjectDTOJSdwMax.size(); j++) {
                String unitConstruction = supervisorProjectDTOJSdwMax.get(j).getUnitConstruction();
                jsNameMaxStr = jsNameMaxStr + unitConstruction + ",";

            }
            if (jsNameMinStr.length() > 0) {
                jsNameMaxStr = jsNameMaxStr.substring(0, jsNameMaxStr.length() - 1);
            }
            if (projectNameMinStr.length() > 0) {
                projectNameMaxStr = projectNameMaxStr.substring(0, projectNameMaxStr.length() - 1);
            }
            data.get(i).setMaxProjectName(projectNameMaxStr);
            data.get(i).setMaxJsName(jsNameMaxStr);

        }
        return data;
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 价格分析查询建设单位的详情
     * @Date:17:10 2021/5/13
     */
    @ApiOperation(value = "/jgfxListDetailJs", httpMethod = "GET", notes = "产品分析")
    @GetMapping(value = "/jgfxListDetailJs")
    @ResponseBody
    public ReType jgfxListDetailJs(SupervisorProjectDTO dto, Model model, String page, String limit) {
        ReType re = new ReType();
        List<SupervisorProjectDTO> data = supervisorProjectService.selectJgJsDw(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 价格分析查询--项目名称
     * @Date:17:10 2021/5/13
     */
    @ApiOperation(value = "/jgfxListDetailPro", httpMethod = "GET", notes = "产品分析")
    @GetMapping(value = "/jgfxListDetailPro")
    @ResponseBody
    public ReType jgfxListDetailPro(SupervisorProjectDTO dto, Model model, String page, String limit) {
        ReType re = new ReType();
        List<SupervisorProjectDTO> data = supervisorProjectService.selectJgPro(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 建设单位详情
     * @Date:18:05 2021/5/13
     */
    @GetMapping("jgfxDetailJsDw")
    public String jgfxDetailJsDw(SupervisorProjectDTO dto, Model model) {
        model.addAttribute("dto", dto);
        return "/decision/jgfx/viewDwDetail";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 价格分析项目详情
     * @Date:18:07 2021/5/13
     */
    @GetMapping("jgfxDetailPro")
    public String jgfxDetailPro(SupervisorProjectDTO dto, Model model) {
        model.addAttribute("dto", dto);
        return "/decision/jgfx/viewProDetail";
    }

    /**
     * 价格分析导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping("exportTable")
    public void exportTable(SupervisorProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        String fileName = "价格分析" + DateUtil.getCurrentDateNoSpliter();
        List<SupervisorProjectDTO> dtos = jgfxList2(dto);
        List exprotList = new ArrayList();
        for (SupervisorProjectDTO dto1 : dtos) {
            dto1.setPriceqj("[" + dto1.getMinNum() + "," + dto1.getMaxNum() + "]");
            exprotList.add(dto1);
        }
        HashMap map1 = new HashMap();
        map1.put("lists", exprotList);
        map1.put("name", "价格分析");
        try {
            ExcelExportUtil.exportExcel(response, map1, fileName, "87005");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 价格分析预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTable")
    public JsonUtil viewTable(SupervisorProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "价格分析" + DateUtil.getCurrentDateNoSpliter();
            List<SupervisorProjectDTO> dtos = jgfxList2(dto);
            List exprotList = new ArrayList();
            for (SupervisorProjectDTO dto1 : dtos) {
                dto1.setPriceqj("[" + dto1.getMinNum() + "," + dto1.getMaxNum() + "]");
                exprotList.add(dto1);
            }
            HashMap map1 = new HashMap();
            map1.put("lists", exprotList);
            map1.put("name", "价格分析");
            File formExcel = createFormExcel("87005", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 价格分析导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping("exportTableOaData")
    public void exportTableOaData(OaReDataDTO dto, HttpServletRequest request, HttpServletResponse response) {
        String fileName = "信息系统统计" + DateUtil.getCurrentDateNoSpliter();
        List<OaData> exprotList = oaDataService.selectList(dto);
        for (OaData oa : exprotList) {
            if ("0".equals(oa.getYwht())) {
                oa.setYwht("是");
            } else {
                oa.setYwht("否");
            }
            if ("0".equals(oa.getSfysfk())) {
                oa.setYwht("是");
            } else {
                oa.setYwht("否");
            }
            if ("0".equals(oa.getSfbhqtyw())) {
                oa.setYwht("是");
            } else {
                oa.setYwht("否");
            }
            if ("0".equals(oa.getYq())) {
                oa.setYwht("是");
            } else {
                oa.setYwht("否");
            }
        }
        HashMap map1 = new HashMap();
        map1.put("lists", exprotList);
        map1.put("name", "信息系统统计");
        try {
            ExcelExportUtil.exportExcel(response, map1, fileName, "87008");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 价格分析预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableOaData")
    public JsonUtil viewTableOaData(OaReDataDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "信息系统统计" + DateUtil.getCurrentDateNoSpliter();
            List<OaData> exprotList = oaDataService.selectList(dto);
            for (OaData oa : exprotList) {
                if ("0".equals(oa.getYwht())) {
                    oa.setYwht("是");
                } else {
                    oa.setYwht("否");
                }
                if ("0".equals(oa.getSfysfk())) {
                    oa.setYwht("是");
                } else {
                    oa.setYwht("否");
                }
                if ("0".equals(oa.getSfbhqtyw())) {
                    oa.setYwht("是");
                } else {
                    oa.setYwht("否");
                }
                if ("0".equals(oa.getYq())) {
                    oa.setYwht("是");
                } else {
                    oa.setYwht("否");
                }
            }
            HashMap map1 = new HashMap();
            map1.put("lists", exprotList);
            map1.put("name", "信息系统统计");
            File formExcel = createFormExcel("87008", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 产品分析导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping("exportTableCp")
    public void exportTableCp(SupervisorProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        String fileName = "产品分析" + DateUtil.getCurrentDateNoSpliter();
        List<SupervisorProjectDTO> exprotList = cpfxList1(dto);

        int num = 0;
        //double ppzb = 0.00;
        int proNum = 0;
        int jsNum = 0;
        for (SupervisorProjectDTO item : exprotList) {
            if(StringUtil.isNotBlank(item.getNum())) {
                num += Integer.parseInt(item.getNum());
            }
            //ppzb += Double.parseDouble(item.getPpzb().replace("%", ""));
            if(StringUtil.isNotBlank(item.getProNum())) {
                proNum += Integer.parseInt(item.getProNum());
            }
            if(StringUtil.isNotBlank(item.getJsNum())) {
                jsNum += Integer.parseInt(item.getJsNum());
            }
        }

        HashMap map1 = new HashMap();
        map1.put("lists", exprotList);
        map1.put("name", "产品分析");
        map1.put("totalNum", num);
        //map1.put("totalPpzb", ppzb + "%");
        map1.put("totalProNum", proNum);
        map1.put("totalJsNum", jsNum);
        try {
            ExcelExportUtil.exportExcel(response, map1, fileName, "87006");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 产品分析预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableCp")
    public JsonUtil viewTableCp(SupervisorProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "产品分析" + DateUtil.getCurrentDateNoSpliter();
            List<SupervisorProjectDTO> exprotList = cpfxList1(dto);
            int num = 0;
            int proNum = 0;
            int jsNum = 0;
            for (SupervisorProjectDTO item : exprotList) {
                if(StringUtil.isNotBlank(item.getNum())) {
                    num += Integer.parseInt(item.getNum());
                }
                if(StringUtil.isNotBlank(item.getProNum())) {
                    proNum += Integer.parseInt(item.getProNum());
                }
                if(StringUtil.isNotBlank(item.getJsNum())) {
                    jsNum += Integer.parseInt(item.getJsNum());
                }
            }
            HashMap map1 = new HashMap();
            map1.put("lists", exprotList);
            map1.put("name", "产品分析");
            map1.put("totalNum", num);
            map1.put("totalProNum", proNum);
            map1.put("totalJsNum", jsNum);
            File formExcel = createFormExcel("87006", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 企业信息导出excel
     *
     * @param request
     * @param response
     */
    @RequestMapping("exportTableQy")
    public void exportTableQy(SysUserDTO dto, HttpServletRequest request, HttpServletResponse response) {
        String fileName = "企业信息统计_" + DateUtil.getCurrentDateNoSpliter();
        List exprotList = selectComTjLists(dto);
        HashMap map1 = new HashMap();
        map1.put("lists", exprotList);
        map1.put("name", "企业信息");
        try {
            ExcelExportUtil.exportExcel(response, map1, fileName, "87007");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 企业信息预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableQy")
    public JsonUtil viewTableQy(SysUserDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "企业信息统计_" + DateUtil.getCurrentDateNoSpliter();
            List exprotList = selectComTjLists(dto);
            HashMap map1 = new HashMap();
            map1.put("lists", exprotList);
            map1.put("name", "企业信息");
            File formExcel = createFormExcel("87007", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 导出数据
     */
    @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
    public void exportExcel(OaReDataDTO dto, HttpServletRequest request, HttpServletResponse response) {
        //用poi的方式导出excel
        XSSFWorkbook xwb = new XSSFWorkbook();
        XSSFSheet sheet = xwb.createSheet("合同信息统计");
        XSSFSheet sheet2 = xwb.createSheet("监理付款情况");
        XSSFSheet sheet3 = xwb.createSheet("咨询付款情况");
        XSSFSheet sheet4 = xwb.createSheet("检测付款情况");
        //设置表格样式
        sheet.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet.setDefaultColumnWidth(25);//设置缺省列宽
        sheet2.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet2.setDefaultColumnWidth(25);//设置缺省列宽
        sheet3.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet3.setDefaultColumnWidth(25);//设置缺省列宽
        sheet4.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet4.setDefaultColumnWidth(25);//设置缺省列宽

        /**
         * 数据库中取出导入到excel的数据
         */
        Map<String, List> data_list = showOaData(dto);
        List<OaReDataDTO> listHt = data_list.get("list1");
        List<JcPayRecordDTO> listjc = data_list.get("list4");
        List<JcPayRecordDTO> listjl = data_list.get("list2");
        List<JcPayRecordDTO> listzx = data_list.get("list3");

        HttpSession session = request.getSession();
        if (session != null) {
            /*MonitorControlProtected mcp = (MonitorControlProtected) session.getAttribute("MONITOR_CONTROL_TABLE_MAP");*/
            String[] titleArr = new String[]{"申请人（销售人员）", "工期", "合同名称", "约定条件", "所属分部", "签订部门", "延期", "区域", "合同金额", "客户名称", "客户联系人", "客户联系方式", "合同额或取费比例", "签订时间", "实施单位信息", "合同编号", "首付款", "项目投资额", "业务类型", "是否有首付款", "行业", "项目实际实施人", "项目名称", "监理项目总监", "监理项目总代", "监理工程师", "咨询项目经理", "高级咨询顾问", "咨询项目组成员", "检测技术负责人", "检测项目经理", "检测项目组成员", "合同状态", "合同签订地省市区", "项目编号", "法人签字", "合同类型", "签章份数", "签章类型", "上传附件", "商机名称", "服务范围", "骑缝章", "法人章", "流程编号", "申请日期", "一般条款", "公章", "合同章", "费率", "工程简要概述", "合同注明的人员情况", "共享人", "监理费计算方式", "质保时长", "分项选择", "分类"};
            String[] titleArr2 = new String[]{"监理合同额", "已回款合计", "已回款比例", "咨询合同额", "已回款合计", "已回款比例", "检测合同额", "已回款合计", "已回款比例"};
            String[] title3 = new String[]{"计划付款时间", "付款方式", "计划付款金额", "计划付款比例", "实际付款时间", "实际付款金额"};
            //表头
            XSSFRow fas_title_row = sheet.createRow(0);//行
            XSSFCell cell0 = fas_title_row.createCell(0);
            cell0.setCellValue("合同系统统计");
            XSSFRow title_row = sheet.createRow(1);//行
            XSSFRow two_title_row = sheet.createRow(2);//行
            for (int x = 0; x < titleArr.length; x++) {
                XSSFCell cell = title_row.createCell(x);
                cell.setCellValue(titleArr[x]);

            }
            //=================================================================================================================
            XSSFRow fas_title_row_jl = sheet2.createRow(0);//行
            XSSFCell cell0_jl = fas_title_row_jl.createCell(0);
            cell0_jl.setCellValue("监理付款情况");
            XSSFRow title_row_jl = sheet2.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_jl.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================
            //=================================================================================================================
            XSSFRow fas_title_row_zx = sheet3.createRow(0);//行
            XSSFCell cell0_zx = fas_title_row_zx.createCell(0);
            cell0_zx.setCellValue("咨询付款情况");
            XSSFRow title_row_zx = sheet3.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_zx.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================
            //=================================================================================================================
            XSSFRow fas_title_row_jc = sheet4.createRow(0);//行
            XSSFCell cell0_jc = fas_title_row_jc.createCell(0);
            cell0_jc.setCellValue("检测付款情况");
            XSSFRow title_row_jc = sheet4.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_jc.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================


            XSSFCell cell1 = title_row.createCell(57);
            cell1.setCellValue("监理付款情况");
            XSSFCell cell2 = title_row.createCell(60);
            cell2.setCellValue("咨询付款情况");
            XSSFCell cell3 = title_row.createCell(63);
            cell3.setCellValue("检测付款情况");
            for (int i = 0; i < titleArr2.length; i++) {
                XSSFCell cell = two_title_row.createCell(i + 57);
                cell.setCellValue(titleArr2[i]);
            }
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 65));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 57, 59));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 60, 62));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 63, 65));
            sheet2.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            sheet3.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            sheet4.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            for (int y = 0; y < 57; y++) {
                sheet.addMergedRegion(new CellRangeAddress(1, 2, y, y));
            }
            if (listHt != null && listHt.size() > 0) {
                for (int i = 0; i < listHt.size(); i++) {
                    OaReDataDTO mcp = listHt.get(i);
                    XSSFRow data_row = sheet.createRow(i + 3);//行

                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getSqr());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getGq());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getHtmc());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getYdtj());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getSsfb());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getQdbm());
                    XSSFCell cell_6 = data_row.createCell(6);
                    cell_6.setCellValue(mcp.getYq());
                    XSSFCell cell_7 = data_row.createCell(7);
                    cell_7.setCellValue(mcp.getXzqy());
                    XSSFCell cell_8 = data_row.createCell(8);
                    cell_8.setCellValue(mcp.getHtje());
                    XSSFCell cell_9 = data_row.createCell(9);
                    cell_9.setCellValue(mcp.getKhmc());
                    XSSFCell cell_10 = data_row.createCell(10);
                    cell_10.setCellValue(mcp.getKhlxr());
                    XSSFCell cell_11 = data_row.createCell(11);
                    cell_11.setCellValue(mcp.getKhlxfs());
                    XSSFCell cell_12 = data_row.createCell(12);
                    cell_12.setCellValue(mcp.getSfbz());
                    XSSFCell cell_13 = data_row.createCell(13);
                    cell_13.setCellValue(mcp.getHtqdrq());
                    XSSFCell cell_14 = data_row.createCell(14);
                    cell_14.setCellValue(mcp.getSsdwmc());
                    XSSFCell cell_15 = data_row.createCell(15);
                    cell_15.setCellValue(mcp.getHtbh());
                    XSSFCell cell_16 = data_row.createCell(16);
                    cell_16.setCellValue(mcp.getSfk());
                    XSSFCell cell_17 = data_row.createCell(17);
                    cell_17.setCellValue(mcp.getXmtze());
                    XSSFCell cell_18 = data_row.createCell(18);
                    cell_18.setCellValue(mcp.getYwlx());
                    XSSFCell cell_19 = data_row.createCell(19);
                    cell_19.setCellValue(mcp.getHy());
                    XSSFCell cell_20 = data_row.createCell(20);
                    cell_20.setCellValue(mcp.getSjssr());
                    XSSFCell cell_21 = data_row.createCell(21);
                    cell_21.setCellValue(mcp.getSfysfk());
                    XSSFCell cell_22 = data_row.createCell(22);
                    cell_22.setCellValue(mcp.getXmmc());
                    XSSFCell cell_23 = data_row.createCell(23);
                    cell_23.setCellValue(mcp.getXmzj());
                    XSSFCell cell_24 = data_row.createCell(24);
                    cell_24.setCellValue(mcp.getXmzd());
                    XSSFCell cell_25 = data_row.createCell(25);
                    cell_25.setCellValue(mcp.getJlgcs());
                    XSSFCell cell_26 = data_row.createCell(26);
                    cell_26.setCellValue(mcp.getZxxmzj());
                    XSSFCell cell_27 = data_row.createCell(27);
                    cell_27.setCellValue(mcp.getZxxmzd());
                    XSSFCell cell_28 = data_row.createCell(28);
                    cell_28.setCellValue(mcp.getZxjlgcs());
                    XSSFCell cell_29 = data_row.createCell(29);
                    cell_29.setCellValue(mcp.getJcjsfzr());
                    XSSFCell cell_30 = data_row.createCell(30);
                    cell_30.setCellValue(mcp.getJcxmjl());
                    XSSFCell cell_31 = data_row.createCell(31);
                    cell_31.setCellValue(mcp.getJcxmzcy());
                    XSSFCell cell_32 = data_row.createCell(32);
                    cell_32.setCellValue(mcp.getHtzt());
                    XSSFCell cell_33 = data_row.createCell(33);
                    cell_33.setCellValue(mcp.getQddd());
                    XSSFCell cell_34 = data_row.createCell(34);
                    cell_34.setCellValue(mcp.getXmbh());
                    XSSFCell cell_35 = data_row.createCell(35);
                    cell_35.setCellValue(mcp.getFrqz());
                    XSSFCell cell_36 = data_row.createCell(36);
                    cell_36.setCellValue(mcp.getHtlx());
                    XSSFCell cell_37 = data_row.createCell(37);
                    cell_37.setCellValue(mcp.getFs());
                    XSSFCell cell_38 = data_row.createCell(38);
                    cell_38.setCellValue(mcp.getQzlx());
                    XSSFCell cell_39 = data_row.createCell(39);
                    cell_39.setCellValue(mcp.getScfj());
                    XSSFCell cell_40 = data_row.createCell(40);
                    cell_40.setCellValue(mcp.getSjmc());
                    XSSFCell cell_41 = data_row.createCell(41);
                    cell_41.setCellValue(mcp.getFwfw());
                    XSSFCell cell_42 = data_row.createCell(42);
                    cell_42.setCellValue(mcp.getQfz());
                    XSSFCell cell_43 = data_row.createCell(43);
                    cell_43.setCellValue(mcp.getFrz());
                    XSSFCell cell_44 = data_row.createCell(44);
                    cell_44.setCellValue(mcp.getLcbh());
                    XSSFCell cell_45 = data_row.createCell(45);
                    cell_45.setCellValue(mcp.getSqrq());
                    XSSFCell cell_46 = data_row.createCell(46);
                    cell_46.setCellValue(mcp.getYbtk());
                    XSSFCell cell_47 = data_row.createCell(47);
                    cell_47.setCellValue(mcp.getGz());
                    XSSFCell cell_48 = data_row.createCell(48);
                    cell_48.setCellValue(mcp.getHtz());
                    XSSFCell cell_49 = data_row.createCell(49);
                    cell_49.setCellValue(mcp.getFl());
                    XSSFCell cell_50 = data_row.createCell(50);
                    cell_50.setCellValue(mcp.getGcjygs());
                    XSSFCell cell_51 = data_row.createCell(51);
                    cell_51.setCellValue(mcp.getRyqk());
                    XSSFCell cell_52 = data_row.createCell(52);
                    cell_52.setCellValue(mcp.getGxr());
                    XSSFCell cell_53 = data_row.createCell(53);
                    cell_53.setCellValue(mcp.getJsfs());
                    XSSFCell cell_54 = data_row.createCell(54);
                    cell_54.setCellValue(mcp.getZbsc());
                    XSSFCell cell_55 = data_row.createCell(55);
                    cell_55.setCellValue(mcp.getFxxz());
                    XSSFCell cell_56 = data_row.createCell(56);
                    cell_56.setCellValue(mcp.getFenlei());
                    XSSFCell cell_57 = data_row.createCell(57);
                    cell_57.setCellValue(mcp.getJlhte());
                    XSSFCell cell_58 = data_row.createCell(58);
                    cell_58.setCellValue(mcp.getJlyhkje());
                    XSSFCell cell_59 = data_row.createCell(59);
                    cell_59.setCellValue(mcp.getJlyhkbl());
                    XSSFCell cell_60 = data_row.createCell(60);
                    cell_60.setCellValue(mcp.getZxhte());
                    XSSFCell cell_61 = data_row.createCell(61);
                    cell_61.setCellValue(mcp.getZxyhkje());
                    XSSFCell cell_62 = data_row.createCell(62);
                    cell_62.setCellValue(mcp.getZxyhkbl());
                    XSSFCell cell_63 = data_row.createCell(63);
                    cell_63.setCellValue(mcp.getJchte());
                    XSSFCell cell_64 = data_row.createCell(64);
                    cell_64.setCellValue(mcp.getJcyhkje());
                    XSSFCell cell_65 = data_row.createCell(65);
                    cell_65.setCellValue(mcp.getJcyhkbl());
                }
            }
            if (listjl != null && listjl.size() > 0) {
                for (int i = 0; i < listjl.size(); i++) {
                    JcPayRecordDTO mcp = listjl.get(i);
                    XSSFRow data_row = sheet2.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            if (listzx != null && listzx.size() > 0) {
                for (int i = 0; i < listzx.size(); i++) {
                    JcPayRecordDTO mcp = listzx.get(i);
                    XSSFRow data_row = sheet3.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            if (listjc != null && listjc.size() > 0) {
                for (int i = 0; i < listjc.size(); i++) {
                    JcPayRecordDTO mcp = listjc.get(i);
                    XSSFRow data_row = sheet4.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            OutputStream output = null;
            try {
                output = response.getOutputStream();
            } catch (IOException e) {
                e.printStackTrace();
            }
            response.reset();
            String filename = null;
            try {
                filename = java.net.URLEncoder.encode("合同信息统计" + System.currentTimeMillis() + ".xlsx", "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";");
            response.setContentType("application/msexcel");
            try {
                xwb.write(output);
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 合同信息预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableHt")
    public JsonUtil viewTableHt(OaReDataDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "合同信息统计_" + DateUtil.getCurrentDateNoSpliter();
            Map<String, List> data_list = showOaData(dto);
            File formExcel = exportExcelYl(data_list, request, response);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    public List<SysUserDTO> selectComTjLists(SysUserDTO dto) {
        List<SysUserDTO> sysUserDTOS = sysUserMapper.selectComTjList(dto);
        return sysUserDTOS;

    }

    public File exportExcelYl(Map<String, List> data_list, HttpServletRequest request, HttpServletResponse response) {
        //用poi的方式导出excel
        XSSFWorkbook xwb = new XSSFWorkbook();
        XSSFSheet sheet = xwb.createSheet("合同信息统计");
        XSSFSheet sheet2 = xwb.createSheet("监理付款情况");
        XSSFSheet sheet3 = xwb.createSheet("咨询付款情况");
        XSSFSheet sheet4 = xwb.createSheet("检测付款情况");
        //设置表格样式
        sheet.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet.setDefaultColumnWidth(25);//设置缺省列宽
        sheet2.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet2.setDefaultColumnWidth(25);//设置缺省列宽
        sheet3.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet3.setDefaultColumnWidth(25);//设置缺省列宽
        sheet4.setDefaultRowHeightInPoints(20);//设置缺省列高
        sheet4.setDefaultColumnWidth(25);//设置缺省列宽

        /**
         * 数据库中取出导入到excel的数据
         */
        List<OaReDataDTO> listHt = data_list.get("list1");
        List<JcPayRecordDTO> listjc = data_list.get("list4");
        List<JcPayRecordDTO> listjl = data_list.get("list2");
        List<JcPayRecordDTO> listzx = data_list.get("list3");

        HttpSession session = request.getSession();
        if (session != null) {
            /*MonitorControlProtected mcp = (MonitorControlProtected) session.getAttribute("MONITOR_CONTROL_TABLE_MAP");*/
            String[] titleArr = new String[]{"申请人（销售人员）", "工期", "合同名称", "约定条件", "所属分部", "签订部门", "延期", "区域", "合同金额", "客户名称", "客户联系人", "客户联系方式", "合同额或取费比例", "签订时间", "实施单位信息", "合同编号", "首付款", "项目投资额", "业务类型", "是否有首付款", "行业", "项目实际实施人", "项目名称", "监理项目总监", "监理项目总代", "监理工程师", "咨询项目经理", "高级咨询顾问", "咨询项目组成员", "检测技术负责人", "检测项目经理", "检测项目组成员", "合同状态", "合同签订地省市区", "项目编号", "法人签字", "合同类型", "签章份数", "签章类型", "上传附件", "商机名称", "服务范围", "骑缝章", "法人章", "流程编号", "申请日期", "一般条款", "公章", "合同章", "费率", "工程简要概述", "合同注明的人员情况", "共享人", "监理费计算方式", "质保时长", "分项选择", "分类"};
            String[] titleArr2 = new String[]{"监理合同额", "已回款合计", "已回款比例", "咨询合同额", "已回款合计", "已回款比例", "检测合同额", "已回款合计", "已回款比例"};
            String[] title3 = new String[]{"计划付款时间", "付款方式", "计划付款金额", "计划付款比例", "实际付款时间", "实际付款金额"};
            //表头
            XSSFRow fas_title_row = sheet.createRow(0);//行
            XSSFCell cell0 = fas_title_row.createCell(0);
            cell0.setCellValue("合同系统统计");
            XSSFRow title_row = sheet.createRow(1);//行
            XSSFRow two_title_row = sheet.createRow(2);//行
            for (int x = 0; x < titleArr.length; x++) {
                XSSFCell cell = title_row.createCell(x);
                cell.setCellValue(titleArr[x]);

            }
            //=================================================================================================================
            XSSFRow fas_title_row_jl = sheet2.createRow(0);//行
            XSSFCell cell0_jl = fas_title_row_jl.createCell(0);
            cell0_jl.setCellValue("监理付款情况");
            XSSFRow title_row_jl = sheet2.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_jl.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================
            //=================================================================================================================
            XSSFRow fas_title_row_zx = sheet3.createRow(0);//行
            XSSFCell cell0_zx = fas_title_row_zx.createCell(0);
            cell0_zx.setCellValue("咨询付款情况");
            XSSFRow title_row_zx = sheet3.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_zx.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================
            //=================================================================================================================
            XSSFRow fas_title_row_jc = sheet4.createRow(0);//行
            XSSFCell cell0_jc = fas_title_row_jc.createCell(0);
            cell0_jc.setCellValue("检测付款情况");
            XSSFRow title_row_jc = sheet4.createRow(1);//行
            for (int x = 0; x < title3.length; x++) {
                XSSFCell cell = title_row_jc.createCell(x);
                cell.setCellValue(title3[x]);

            }
            //=================================================================================================================


            XSSFCell cell1 = title_row.createCell(57);
            cell1.setCellValue("监理付款情况");
            XSSFCell cell2 = title_row.createCell(60);
            cell2.setCellValue("咨询付款情况");
            XSSFCell cell3 = title_row.createCell(63);
            cell3.setCellValue("检测付款情况");
            for (int i = 0; i < titleArr2.length; i++) {
                XSSFCell cell = two_title_row.createCell(i + 57);
                cell.setCellValue(titleArr2[i]);
            }
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 65));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 57, 59));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 60, 62));
            sheet.addMergedRegion(new CellRangeAddress(1, 1, 63, 65));
            sheet2.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            sheet3.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            sheet4.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
            for (int y = 0; y < 57; y++) {
                sheet.addMergedRegion(new CellRangeAddress(1, 2, y, y));
            }
            if (listHt != null && listHt.size() > 0) {
                for (int i = 0; i < listHt.size(); i++) {
                    OaReDataDTO mcp = listHt.get(i);
                    XSSFRow data_row = sheet.createRow(i + 3);//行

                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getSqr());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getGq());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getHtmc());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getYdtj());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getSsfb());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getQdbm());
                    XSSFCell cell_6 = data_row.createCell(6);
                    cell_6.setCellValue(mcp.getYq());
                    XSSFCell cell_7 = data_row.createCell(7);
                    cell_7.setCellValue(mcp.getXzqy());
                    XSSFCell cell_8 = data_row.createCell(8);
                    cell_8.setCellValue(mcp.getHtje());
                    XSSFCell cell_9 = data_row.createCell(9);
                    cell_9.setCellValue(mcp.getKhmc());
                    XSSFCell cell_10 = data_row.createCell(10);
                    cell_10.setCellValue(mcp.getKhlxr());
                    XSSFCell cell_11 = data_row.createCell(11);
                    cell_11.setCellValue(mcp.getKhlxfs());
                    XSSFCell cell_12 = data_row.createCell(12);
                    cell_12.setCellValue(mcp.getSfbz());
                    XSSFCell cell_13 = data_row.createCell(13);
                    cell_13.setCellValue(mcp.getHtqdrq());
                    XSSFCell cell_14 = data_row.createCell(14);
                    cell_14.setCellValue(mcp.getSsdwmc());
                    XSSFCell cell_15 = data_row.createCell(15);
                    cell_15.setCellValue(mcp.getHtbh());
                    XSSFCell cell_16 = data_row.createCell(16);
                    cell_16.setCellValue(mcp.getSfk());
                    XSSFCell cell_17 = data_row.createCell(17);
                    cell_17.setCellValue(mcp.getXmtze());
                    XSSFCell cell_18 = data_row.createCell(18);
                    cell_18.setCellValue(mcp.getYwlx());
                    XSSFCell cell_19 = data_row.createCell(19);
                    cell_19.setCellValue(mcp.getHy());
                    XSSFCell cell_20 = data_row.createCell(20);
                    cell_20.setCellValue(mcp.getSjssr());
                    XSSFCell cell_21 = data_row.createCell(21);
                    cell_21.setCellValue(mcp.getSfysfk());
                    XSSFCell cell_22 = data_row.createCell(22);
                    cell_22.setCellValue(mcp.getXmmc());
                    XSSFCell cell_23 = data_row.createCell(23);
                    cell_23.setCellValue(mcp.getXmzj());
                    XSSFCell cell_24 = data_row.createCell(24);
                    cell_24.setCellValue(mcp.getXmzd());
                    XSSFCell cell_25 = data_row.createCell(25);
                    cell_25.setCellValue(mcp.getJlgcs());
                    XSSFCell cell_26 = data_row.createCell(26);
                    cell_26.setCellValue(mcp.getZxxmzj());
                    XSSFCell cell_27 = data_row.createCell(27);
                    cell_27.setCellValue(mcp.getZxxmzd());
                    XSSFCell cell_28 = data_row.createCell(28);
                    cell_28.setCellValue(mcp.getZxjlgcs());
                    XSSFCell cell_29 = data_row.createCell(29);
                    cell_29.setCellValue(mcp.getJcjsfzr());
                    XSSFCell cell_30 = data_row.createCell(30);
                    cell_30.setCellValue(mcp.getJcxmjl());
                    XSSFCell cell_31 = data_row.createCell(31);
                    cell_31.setCellValue(mcp.getJcxmzcy());
                    XSSFCell cell_32 = data_row.createCell(32);
                    cell_32.setCellValue(mcp.getHtzt());
                    XSSFCell cell_33 = data_row.createCell(33);
                    cell_33.setCellValue(mcp.getQddd());
                    XSSFCell cell_34 = data_row.createCell(34);
                    cell_34.setCellValue(mcp.getXmbh());
                    XSSFCell cell_35 = data_row.createCell(35);
                    cell_35.setCellValue(mcp.getFrqz());
                    XSSFCell cell_36 = data_row.createCell(36);
                    cell_36.setCellValue(mcp.getHtlx());
                    XSSFCell cell_37 = data_row.createCell(37);
                    cell_37.setCellValue(mcp.getFs());
                    XSSFCell cell_38 = data_row.createCell(38);
                    cell_38.setCellValue(mcp.getQzlx());
                    XSSFCell cell_39 = data_row.createCell(39);
                    cell_39.setCellValue(mcp.getScfj());
                    XSSFCell cell_40 = data_row.createCell(40);
                    cell_40.setCellValue(mcp.getSjmc());
                    XSSFCell cell_41 = data_row.createCell(41);
                    cell_41.setCellValue(mcp.getFwfw());
                    XSSFCell cell_42 = data_row.createCell(42);
                    cell_42.setCellValue(mcp.getQfz());
                    XSSFCell cell_43 = data_row.createCell(43);
                    cell_43.setCellValue(mcp.getFrz());
                    XSSFCell cell_44 = data_row.createCell(44);
                    cell_44.setCellValue(mcp.getLcbh());
                    XSSFCell cell_45 = data_row.createCell(45);
                    cell_45.setCellValue(mcp.getSqrq());
                    XSSFCell cell_46 = data_row.createCell(46);
                    cell_46.setCellValue(mcp.getYbtk());
                    XSSFCell cell_47 = data_row.createCell(47);
                    cell_47.setCellValue(mcp.getGz());
                    XSSFCell cell_48 = data_row.createCell(48);
                    cell_48.setCellValue(mcp.getHtz());
                    XSSFCell cell_49 = data_row.createCell(49);
                    cell_49.setCellValue(mcp.getFl());
                    XSSFCell cell_50 = data_row.createCell(50);
                    cell_50.setCellValue(mcp.getGcjygs());
                    XSSFCell cell_51 = data_row.createCell(51);
                    cell_51.setCellValue(mcp.getRyqk());
                    XSSFCell cell_52 = data_row.createCell(52);
                    cell_52.setCellValue(mcp.getGxr());
                    XSSFCell cell_53 = data_row.createCell(53);
                    cell_53.setCellValue(mcp.getJsfs());
                    XSSFCell cell_54 = data_row.createCell(54);
                    cell_54.setCellValue(mcp.getZbsc());
                    XSSFCell cell_55 = data_row.createCell(55);
                    cell_55.setCellValue(mcp.getFxxz());
                    XSSFCell cell_56 = data_row.createCell(56);
                    cell_56.setCellValue(mcp.getFenlei());
                    XSSFCell cell_57 = data_row.createCell(57);
                    cell_57.setCellValue(mcp.getJlhte());
                    XSSFCell cell_58 = data_row.createCell(58);
                    cell_58.setCellValue(mcp.getJlyhkje());
                    XSSFCell cell_59 = data_row.createCell(59);
                    cell_59.setCellValue(mcp.getJlyhkbl());
                    XSSFCell cell_60 = data_row.createCell(60);
                    cell_60.setCellValue(mcp.getZxhte());
                    XSSFCell cell_61 = data_row.createCell(61);
                    cell_61.setCellValue(mcp.getZxyhkje());
                    XSSFCell cell_62 = data_row.createCell(62);
                    cell_62.setCellValue(mcp.getZxyhkbl());
                    XSSFCell cell_63 = data_row.createCell(63);
                    cell_63.setCellValue(mcp.getJchte());
                    XSSFCell cell_64 = data_row.createCell(64);
                    cell_64.setCellValue(mcp.getJcyhkje());
                    XSSFCell cell_65 = data_row.createCell(65);
                    cell_65.setCellValue(mcp.getJcyhkbl());
                }
            }
            if (listjl != null && listjl.size() > 0) {
                for (int i = 0; i < listjl.size(); i++) {
                    JcPayRecordDTO mcp = listjl.get(i);
                    XSSFRow data_row = sheet2.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            if (listzx != null && listzx.size() > 0) {
                for (int i = 0; i < listzx.size(); i++) {
                    JcPayRecordDTO mcp = listzx.get(i);
                    XSSFRow data_row = sheet3.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            if (listjc != null && listjc.size() > 0) {
                for (int i = 0; i < listjc.size(); i++) {
                    JcPayRecordDTO mcp = listjc.get(i);
                    XSSFRow data_row = sheet4.createRow(i + 2);//行
                    XSSFCell cell_0 = data_row.createCell(0);
                    cell_0.setCellValue(mcp.getJhDate());
                    XSSFCell cell_1 = data_row.createCell(1);
                    cell_1.setCellValue(mcp.getBadtName());
                    XSSFCell cell_2 = data_row.createCell(2);
                    cell_2.setCellValue(mcp.getPayMoney());
                    XSSFCell cell_3 = data_row.createCell(3);
                    cell_3.setCellValue(mcp.getSppPersent());
                    XSSFCell cell_4 = data_row.createCell(4);
                    cell_4.setCellValue(mcp.getArrivalDate());
                    XSSFCell cell_5 = data_row.createCell(5);
                    cell_5.setCellValue(mcp.getArrivalMoney());
                }
            }
            String filename = null;
            // 将excel内容写入到文件当中
            try {
                filename = java.net.URLEncoder.encode("合同信息统计" + System.currentTimeMillis(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            }
            response.setHeader("Content-Disposition", "attachment; filename=" + filename + ";");
            response.setContentType("application/msexcel");
            // 文件路径
            String filePath = uploadUtil.getTempPath() + filename + ".xls";// 含文件名的全路径，如果是2007及以后的版本，后缀可用.xlsx，向前兼容
            File file = new File(filePath);

            // 如果已存在,删除旧文件
            if (file.exists()) {
                file.delete();
            }

            try {
                file.createNewFile();
                FileOutputStream fileOut = new FileOutputStream(file);
                xwb.write(fileOut);
                fileOut.close();
                return file;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
        return null;
    }

    @GetMapping("/exportExcelProZx")
    public void exportExcelProZx(ZxProjectDTO dto, Model model, HttpServletResponse response) {
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<ZxProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = zxProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
                    List<ZxPayRecordDTO> data1 = zxPayRecordService.selectPayRecord(dto);
                    List dataEx = new ArrayList();
                    for (int i = 0; i < data1.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", data1.get(i).getZfMoney());
                        mapdata.put("createDate", data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName = project.getProjectName() + "项目已开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName", project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    ZxProject project003 = zxProjectService.selectByPrimaryKey(projectId003);
                    List<ZxPayRecordDTO> data003 = zxPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    ZxProjectPay pay = new ZxProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<ZxProjectPay> pays = zxProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List dataEx003 = new ArrayList();
                    List<ZxPayRecord> prs = new ArrayList<ZxPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            ZxPayRecord dtomony = new ZxPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap mapdata = new HashMap();
                            mapdata.put("index", i + 1);
                            mapdata.put("zfMoney", result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName = project003.getProjectName() + "项目未开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName", project003.getProjectName());
                    ptid = "204";
                    break;
                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    ZxProject project004 = zxProjectService.selectByPrimaryKey(projectId004);
                    List<ZxPayRecordDTO> AlistData = zxPayRecordService.selectPayRecordDe(dto);
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    List dataEx004 = new ArrayList();

                    for (int i = 0; i < AlistData.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent", AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName", AlistData.get(i).getMilepostName());
                        mapdata.put("createDate", AlistData.get(i).getCreateDate());
                        String status = "";
                        if ("001".equals(AlistData.get(i).getJsStatus())) {
                            status = "提前";
                        } else if ("002".equals(AlistData.get(i).getJsStatus())) {
                            status = "按时";
                        } else if ("003".equals(AlistData.get(i).getJsStatus())) {
                            status = "延期";
                        }
                        mapdata.put("jsStatus", status);
                        dataEx004.add(mapdata);
                    }
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx004);
                    map.put("projectName", project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    ZxProject project005 = zxProjectService.selectByPrimaryKey(projectId005);
                    List<ZxPayRecordDTO> data005 = zxPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal = jes;
                    ZxProjectPayDTO payDTO = new ZxProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<ZxProjectPayDTO> zxProjectPayDTOS = zxProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<ZxProjectPayDTO> list = new ArrayList<>();
                    for (int i = 0; i < zxProjectPayDTOS.size(); i++) {
                        ZxProjectPayDTO payDTO1 = zxProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if (paytotal.compareTo(moneypay) < 0) {
                            if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                                paytotal = new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal = paytotal.subtract(moneypay);

                        ZxProjectMilepost milepostnew = new ZxProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<ZxProjectMilepost> milepostcurr = zxProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String zxProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        ZxProjectStage stage = zxProjectStageService.selectByPrimaryKey(zxProjectStageId);
                        String payMiseNoDate = zxProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        zxProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist = new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", list.get(i).getPayMoney());
                        mapdata.put("sppPersent", list.get(i).getSppPersent());
                        mapdata.put("milepostName", list.get(i).getMilepostName());
                        mapdata.put("createDate", list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName = project005.getProjectName() + "项目未回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName", project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            ExcelExportUtil.exportExcel(response, map, fileName, ptid);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    /**
     * 预览表格
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/viewExcelProZx")
    public JsonUtil viewExcelProZx(ZxProjectDTO dto, Model model, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<ZxProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = zxProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    ZxProject project = zxProjectService.selectByPrimaryKey(projectId);
                    List<ZxPayRecordDTO> data1 = zxPayRecordService.selectPayRecord(dto);
                    List dataEx = new ArrayList();
                    for (int i = 0; i < data1.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", data1.get(i).getZfMoney());
                        mapdata.put("createDate", data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName = project.getProjectName() + "项目已开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName", project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    ZxProject project003 = zxProjectService.selectByPrimaryKey(projectId003);
                    List<ZxPayRecordDTO> data003 = zxPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    ZxProjectPay pay = new ZxProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<ZxProjectPay> pays = zxProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List dataEx003 = new ArrayList();
                    List<ZxPayRecord> prs = new ArrayList<ZxPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            ZxPayRecord dtomony = new ZxPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap mapdata = new HashMap();
                            mapdata.put("index", i + 1);
                            mapdata.put("zfMoney", result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName = project003.getProjectName() + "项目未开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName", project003.getProjectName());
                    ptid = "204";
                    break;

                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    ZxProject project004 = zxProjectService.selectByPrimaryKey(projectId004);
                    List<ZxPayRecordDTO> AlistData = zxPayRecordService.selectPayRecordDe(dto);
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    List dataEx004 = new ArrayList();
                    for (int i = 0; i < AlistData.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent", AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName", AlistData.get(i).getMilepostName());
                        mapdata.put("createDate", AlistData.get(i).getCreateDate());
                        String status = "";
                        if ("001".equals(AlistData.get(i).getJsStatus())) {
                            status = "提前";
                        } else if ("002".equals(AlistData.get(i).getJsStatus())) {
                            status = "按时";
                        } else if ("003".equals(AlistData.get(i).getJsStatus())) {
                            status = "延期";
                        }
                        mapdata.put("jsStatus", status);
                        dataEx004.add(mapdata);
                    }
                    map.put("records", dataEx004);
                    map.put("projectName", project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    ZxProject project005 = zxProjectService.selectByPrimaryKey(projectId005);
                    List<ZxPayRecordDTO> data005 = zxPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal = jes;
                    ZxProjectPayDTO payDTO = new ZxProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<ZxProjectPayDTO> zxProjectPayDTOS = zxProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<ZxProjectPayDTO> list = new ArrayList<>();
                    for (int i = 0; i < zxProjectPayDTOS.size(); i++) {
                        ZxProjectPayDTO payDTO1 = zxProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if (paytotal.compareTo(moneypay) < 0) {
                            if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                                paytotal = new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal = paytotal.subtract(moneypay);

                        ZxProjectMilepost milepostnew = new ZxProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<ZxProjectMilepost> milepostcurr = zxProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String zxProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        ZxProjectStage stage = zxProjectStageService.selectByPrimaryKey(zxProjectStageId);
                        String payMiseNoDate = zxProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        zxProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist = new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", list.get(i).getPayMoney());
                        mapdata.put("sppPersent", list.get(i).getSppPersent());
                        mapdata.put("milepostName", list.get(i).getMilepostName());
                        mapdata.put("createDate", list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName = project005.getProjectName() + "项目未回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName", project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            File formExcel = createFormExcel(ptid, fileName, map);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);

            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
        return result;
    }


    //======================================================================================================================


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description:
     * @Date:14:51 2021/5/11
     */
    @ApiOperation(value = "/selectYKfPListJc", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectYKfPListJc")
    @ResponseBody
    public ReType selectYKfPListJc(JcProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        re.setPageNum(Long.valueOf(page));
        re.setCount(data.size());
        re.setData(data);
        return re;

    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:已开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/viewYKfPJc")
    public String viewYKfPJc(JcProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        JcProject project = jcProjectService.selectByPrimaryKey(projectId);
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if (StringUtil.isNotBlank(fpMoney)) {
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已开票金额共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYkFpJc";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description:未开发票金额
     * @Date:15:44 2021/5/28
     */
    @GetMapping(value = "/noviewYKfPJc")
    public String noviewYKfPJc(JcProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        JcProject project = jcProjectService.selectByPrimaryKey(projectId);
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        // 已开发票金额
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if (StringUtil.isNotBlank(fpMoney)) {
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }
        }
        BigDecimal fpmoney = je;
        String htMoney = project.getHtMoney();
        BigDecimal htMoneyDe = new BigDecimal(htMoney);

        // 查询设置的回款节点
        JcProjectPay pay = new JcProjectPay();
        pay.setSppPrjid(projectId);
        List<JcProjectPay> pays = jcProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        //   25  50  20  30
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        if (htMoneyDe.compareTo(je) == 1) {

            BigDecimal result2 = htMoneyDe.subtract(fpmoney);
            String jsfpstr = result2.stripTrailingZeros().toPlainString();
            String str = "未开票金额共" + num + "笔，共" + jsfpstr + "元";
            model.addAttribute("moneystr", str);
        }
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNoYkFpJc";
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 查询未开发票金额
     * @Date:16:25 2021/5/28
     */
    @ApiOperation(value = "/selectNoKfPListJc", httpMethod = "GET", notes = "已开发票金额")
    @GetMapping(value = "/selectNoKfPListJc")
    @ResponseBody
    public ReType selectNoKfPListJc(JcProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String fpMoney = data.get(i).getFpMoney();
            if (StringUtil.isNotBlank(fpMoney)) {
                BigDecimal addfpMoney = new BigDecimal(fpMoney);
                je = je.add(addfpMoney);
            }

        }
        // 查询设置的回款节点
        JcProjectPay pay = new JcProjectPay();
        pay.setSppPrjid(projectId);
        List<JcProjectPay> pays = jcProjectPayService.select(pay);
        BigDecimal total = new BigDecimal("0.0");
        int num = 0;
        List<JcPayRecord> prs = new ArrayList<JcPayRecord>();
        for (int i = 0; i < pays.size(); i++) {
            String money = pays.get(i).getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal addfpMoney = new BigDecimal(money);
                // 支付的发票总金额 和 设置的付款比例比较
                if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                    // 如果大于设置的比例
                    je = je.subtract(addfpMoney);
                } else {
                    BigDecimal result2 = addfpMoney.subtract(je);
                    JcPayRecord dtomony = new JcPayRecord();
                    dtomony.setFpMoney(result2.toString());
                    prs.add(dtomony);
                    je = new BigDecimal(0.0);
                    num++;
                    // 存在一笔 未开发票金额
                }
            }
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(prs.size());
        re.setData(prs);
        return re;

    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:18:00 2021/5/28
     */
    @GetMapping(value = "/viewYhkjeJc")
    public String viewYhkjeJc(JcProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        JcProject project = jcProjectService.selectByPrimaryKey(projectId);
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addzfMoney = new BigDecimal(zfMoney);
                je = je.add(addzfMoney);
            }

        }
        String jsfpstr = je.stripTrailingZeros().toPlainString();
        String str = "已回款共" + data.size() + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewYhkjeJc";
    }

    /**
     * @param dto
     * @param model
     * @Author:zhaoyongke
     * @Description: 待回款金额
     * @Date:9:44 2021/5/29
     */
    @GetMapping(value = "/viewNohkjeJc")
    public String viewNohkjeJc(JcProjectDTO dto, Model model) {
        String projectId = dto.getProjectId();
        JcProject project = jcProjectService.selectByPrimaryKey(projectId);
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        JcProjectPayDTO payDTO = new JcProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<JcProjectPayDTO> jcProjectPayDTOS = jcProjectPayService.selectSupervisorProjectPay(payDTO);
        List<JcProjectPayDTO> list = new ArrayList<>();
        int numno = 0;
        BigDecimal decimalno = new BigDecimal("0.0");
        for (int i = 0; i < jcProjectPayDTOS.size(); i++) {
            JcProjectPayDTO payDTO1 = jcProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    numno++;
                    decimalno = decimalno.add(moneypay.subtract(paytotal));
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }

        }
        String jsfpstr = decimalno.stripTrailingZeros().toPlainString();
        String str = "未回款共" + numno + "笔，共" + jsfpstr + "元";
        model.addAttribute("moneystr", str);
        model.addAttribute("projectId", projectId);
        model.addAttribute("project", project);
        return "/decision/buProjectInfo/viewNohkjeJc";
    }

    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 未回款金额
     * @Date:9:57 2021/5/29
     */
    @ApiOperation(value = "/selectNohkjeJc", httpMethod = "GET", notes = "未回款金额")
    @GetMapping(value = "/selectNohkjeJc")
    @ResponseBody
    public ReType selectNohkjeJc(JcProjectDTO dto, Model model, String page, String limit) {
        //已经结束状态
        ReType re = new ReType();
        String projectId = dto.getProjectId();
        List<JcPayRecordDTO> data = jcPayRecordService.selectPayRecord(dto);
        BigDecimal je = new BigDecimal("0.0");
        for (int i = 0; i < data.size(); i++) {
            String zfMoney = data.get(i).getZfMoney();
            if (StringUtil.isNotBlank(zfMoney)) {
                BigDecimal addfpMoney = new BigDecimal(zfMoney);
                je = je.add(addfpMoney);
            }

        }
        BigDecimal paytotal = je;
        JcProjectPayDTO payDTO = new JcProjectPayDTO();
        payDTO.setSppPrjid(dto.getProjectId());
        List<JcProjectPayDTO> jcProjectPayDTOS = jcProjectPayService.selectSupervisorProjectPay(payDTO);
        List<JcProjectPayDTO> list = new ArrayList<>();
        for (int i = 0; i < jcProjectPayDTOS.size(); i++) {
            JcProjectPayDTO payDTO1 = jcProjectPayDTOS.get(i);
            String sppNo = payDTO1.getSppNode();
            String money = payDTO1.getPayMoney();
            if (StringUtil.isNotBlank(money)) {
                BigDecimal moneypay = new BigDecimal(money);
                if (paytotal.compareTo(moneypay) < 0) {
                    if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                        paytotal = new BigDecimal("0.0");
                    }
                    payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                    list.add(payDTO1);
                }
                paytotal = paytotal.subtract(moneypay);
            }
            JcProjectMilepost milepostnew = new JcProjectMilepost();
            milepostnew.setMilepostNo(sppNo);
            milepostnew.setProjectId(dto.getProjectId());
            List<JcProjectMilepost> milepostcurr = jcProjectMilepostService.select(milepostnew);
            // 阶段Id
            String jcProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
            JcProjectStage stage = jcProjectStageService.selectByPrimaryKey(jcProjectStageId);
            String payMiseNoDate = jcProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
            jcProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
        }
        re.setPageNum(Long.valueOf(page));
        re.setCount(list.size());
        re.setData(list);
        return re;

    }

    /**
     * @param dtopro
     * @Author:zhaoyongke
     * @Description: 已汇款金额
     * @Date:17:59 2021/5/28
     */
    @ResponseBody
    @GetMapping(value = "/getlistYhkJeJc")
    public ReType getlistYhkJeJc(JcProjectDTO dtopro) {
        ReType re = new ReType();
        try {
            List<JcPayRecordDTO> AlistData = jcPayRecordService.selectPayRecordDe(dtopro);
            re.setCode(0);
            re.setData(AlistData);
        } catch (Exception e) {
            e.printStackTrace();
            re.setCode(500);
            re.setMsg("根据项目编号获取付款方式异常！！" + e.getMessage());
        }
        return re;
    }

    @GetMapping("/exportExcelProJc")
    public void exportExcelProJc(JcProjectDTO dto, Model model, HttpServletResponse response) {
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<JcProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = jcProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    JcProject project = jcProjectService.selectByPrimaryKey(projectId);
                    List<JcPayRecordDTO> data1 = jcPayRecordService.selectPayRecord(dto);
                    List dataEx = new ArrayList();
                    for (int i = 0; i < data1.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", data1.get(i).getZfMoney());
                        mapdata.put("createDate", data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName = project.getProjectName() + "项目已开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName", project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    JcProject project003 = jcProjectService.selectByPrimaryKey(projectId003);
                    List<JcPayRecordDTO> data003 = jcPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    JcProjectPay pay = new JcProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<JcProjectPay> pays = jcProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List dataEx003 = new ArrayList();
                    List<JcPayRecord> prs = new ArrayList<JcPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            JcPayRecord dtomony = new JcPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap mapdata = new HashMap();
                            mapdata.put("index", i + 1);
                            mapdata.put("zfMoney", result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName = project003.getProjectName() + "项目未开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName", project003.getProjectName());
                    ptid = "204";
                    break;
                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    JcProject project004 = jcProjectService.selectByPrimaryKey(projectId004);
                    List<JcPayRecordDTO> AlistData = jcPayRecordService.selectPayRecordDe(dto);
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    List dataEx004 = new ArrayList();

                    for (int i = 0; i < AlistData.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent", AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName", AlistData.get(i).getMilepostName());
                        mapdata.put("createDate", AlistData.get(i).getCreateDate());
                        String status = "";
                        if ("001".equals(AlistData.get(i).getJsStatus())) {
                            status = "提前";
                        } else if ("002".equals(AlistData.get(i).getJsStatus())) {
                            status = "按时";
                        } else if ("003".equals(AlistData.get(i).getJsStatus())) {
                            status = "延期";
                        }
                        mapdata.put("jsStatus", status);
                        dataEx004.add(mapdata);
                    }
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx004);
                    map.put("projectName", project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    JcProject project005 = jcProjectService.selectByPrimaryKey(projectId005);
                    List<JcPayRecordDTO> data005 = jcPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal = jes;
                    JcProjectPayDTO payDTO = new JcProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<JcProjectPayDTO> jcProjectPayDTOS = jcProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<JcProjectPayDTO> list = new ArrayList<>();
                    for (int i = 0; i < jcProjectPayDTOS.size(); i++) {
                        JcProjectPayDTO payDTO1 = jcProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if (paytotal.compareTo(moneypay) < 0) {
                            if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                                paytotal = new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal = paytotal.subtract(moneypay);

                        JcProjectMilepost milepostnew = new JcProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<JcProjectMilepost> milepostcurr = jcProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String jcProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        JcProjectStage stage = jcProjectStageService.selectByPrimaryKey(jcProjectStageId);
                        String payMiseNoDate = jcProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        jcProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist = new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", list.get(i).getPayMoney());
                        mapdata.put("sppPersent", list.get(i).getSppPersent());
                        mapdata.put("milepostName", list.get(i).getMilepostName());
                        mapdata.put("createDate", list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName = project005.getProjectName() + "项目未回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName", project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            ExcelExportUtil.exportExcel(response, map, fileName, ptid);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    /**
     * 预览表格
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/viewExcelProJc")
    public JsonUtil viewExcelProJc(JcProjectDTO dto, Model model, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String exCode = dto.getExCode();
            String fileName = "";
            String ptid = "";
            HashMap map = new HashMap();
            switch (exCode) {
                case "001":
                    // 项目完成率导出
                    List<JcProjectDTO> data = new ArrayList<>();
                    if ("001".equals(dto.getProjectType()) || StringUtil.isBlank(dto.getProjectType())) {
                        data = jcProjectService.selectProFinishLv(dto);
                    }
                    fileName = "项目完成率";
                    map.put("records", data);
                    ptid = "202";
                    break;
                case "002":
                    // 已开发票金额导出
                    String projectId = dto.getProjectId();
                    JcProject project = jcProjectService.selectByPrimaryKey(projectId);
                    List<JcPayRecordDTO> data1 = jcPayRecordService.selectPayRecord(dto);
                    List dataEx = new ArrayList();
                    for (int i = 0; i < data1.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", data1.get(i).getZfMoney());
                        mapdata.put("createDate", data1.get(i).getCreateDate());
                        dataEx.add(mapdata);
                    }
                    fileName = project.getProjectName() + "项目已开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx);
                    map.put("projectName", project.getProjectName());
                    ptid = "203";
                    break;
                case "003":
                    // 未开发票金额
                    String projectId003 = dto.getProjectId();
                    JcProject project003 = jcProjectService.selectByPrimaryKey(projectId003);
                    List<JcPayRecordDTO> data003 = jcPayRecordService.selectPayRecord(dto);
                    BigDecimal je = new BigDecimal("0.0");
                    for (int i = 0; i < data003.size(); i++) {
                        String fpMoney = data003.get(i).getFpMoney();
                        BigDecimal addfpMoney = new BigDecimal(fpMoney);
                        je = je.add(addfpMoney);
                    }
                    // 查询设置的回款节点
                    JcProjectPay pay = new JcProjectPay();
                    pay.setSppPrjid(projectId003);
                    List<JcProjectPay> pays = jcProjectPayService.select(pay);
                    BigDecimal total = new BigDecimal("0.0");
                    int num = 0;
                    List dataEx003 = new ArrayList();
                    List<JcPayRecord> prs = new ArrayList<JcPayRecord>();
                    for (int i = 0; i < pays.size(); i++) {
                        String money = pays.get(i).getPayMoney();
                        BigDecimal addfpMoney = new BigDecimal(money);
                        // 支付的发票总金额 和 设置的付款比例比较
                        if (je.compareTo(addfpMoney) == 0 || je.compareTo(addfpMoney) == 1) {
                            // 如果大于设置的比例
                            je = je.subtract(addfpMoney);
                        } else {
                            BigDecimal result2 = addfpMoney.subtract(je);
                            JcPayRecord dtomony = new JcPayRecord();
                            dtomony.setFpMoney(result2.toString());
                            HashMap mapdata = new HashMap();
                            mapdata.put("index", i + 1);
                            mapdata.put("zfMoney", result2.toString());
                            dataEx003.add(mapdata);
                            prs.add(dtomony);
                            je = new BigDecimal(0.0);
                            num++;
                            // 存在一笔 未开发票金额
                        }
                    }
                    fileName = project003.getProjectName() + "项目未开发票金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", dataEx003);
                    map.put("projectName", project003.getProjectName());
                    ptid = "204";
                    break;

                case "004":
                    //已回款金额
                    String projectId004 = dto.getProjectId();
                    JcProject project004 = jcProjectService.selectByPrimaryKey(projectId004);
                    List<JcPayRecordDTO> AlistData = jcPayRecordService.selectPayRecordDe(dto);
                    fileName = project004.getProjectName() + "项目已回款金额" + DateUtil.getCurrentDateNoSpliter();
                    List dataEx004 = new ArrayList();
                    for (int i = 0; i < AlistData.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", AlistData.get(i).getZfMoney());
                        mapdata.put("sppPersent", AlistData.get(i).getSppPersent());
                        mapdata.put("milepostName", AlistData.get(i).getMilepostName());
                        mapdata.put("createDate", AlistData.get(i).getCreateDate());
                        String status = "";
                        if ("001".equals(AlistData.get(i).getJsStatus())) {
                            status = "提前";
                        } else if ("002".equals(AlistData.get(i).getJsStatus())) {
                            status = "按时";
                        } else if ("003".equals(AlistData.get(i).getJsStatus())) {
                            status = "延期";
                        }
                        mapdata.put("jsStatus", status);
                        dataEx004.add(mapdata);
                    }
                    map.put("records", dataEx004);
                    map.put("projectName", project004.getProjectName());
                    ptid = "205";
                    break;
                case "005":
                    // 未回款金额
                    String projectId005 = dto.getProjectId();
                    JcProject project005 = jcProjectService.selectByPrimaryKey(projectId005);
                    List<JcPayRecordDTO> data005 = jcPayRecordService.selectPayRecord(dto);
                    BigDecimal jes = new BigDecimal("0.0");
                    for (int i = 0; i < data005.size(); i++) {
                        String zfMoney = data005.get(i).getZfMoney();
                        BigDecimal addfpMoney = new BigDecimal(zfMoney);
                        jes = jes.add(addfpMoney);
                    }
                    BigDecimal paytotal = jes;
                    JcProjectPayDTO payDTO = new JcProjectPayDTO();
                    payDTO.setSppPrjid(dto.getProjectId());
                    List<JcProjectPayDTO> jcProjectPayDTOS = jcProjectPayService.selectSupervisorProjectPay(payDTO);
                    List<JcProjectPayDTO> list = new ArrayList<>();
                    for (int i = 0; i < jcProjectPayDTOS.size(); i++) {
                        JcProjectPayDTO payDTO1 = jcProjectPayDTOS.get(i);
                        String sppNo = payDTO1.getSppNode();
                        String money = payDTO1.getPayMoney();
                        BigDecimal moneypay = new BigDecimal(money);
                        if (paytotal.compareTo(moneypay) < 0) {
                            if (paytotal.compareTo(new BigDecimal("0.0")) < 0) {
                                paytotal = new BigDecimal("0.0");
                            }
                            payDTO1.setPayMoney(moneypay.subtract(paytotal).toString());
                            list.add(payDTO1);
                        }
                        paytotal = paytotal.subtract(moneypay);

                        JcProjectMilepost milepostnew = new JcProjectMilepost();
                        milepostnew.setMilepostNo(sppNo);
                        milepostnew.setProjectId(dto.getProjectId());
                        List<JcProjectMilepost> milepostcurr = jcProjectMilepostService.select(milepostnew);
                        // 阶段Id
                        String jcProjectStageId = milepostcurr.get(0).getSupervisorProjectStageId();
                        JcProjectStage stage = jcProjectStageService.selectByPrimaryKey(jcProjectStageId);
                        String payMiseNoDate = jcProjectService.getPayMiseNoDate(stage, milepostcurr.get(0));
                        jcProjectPayDTOS.get(i).setCreateDate(payMiseNoDate);
                    }
                    List datalist = new ArrayList();
                    for (int i = 0; i < list.size(); i++) {
                        HashMap mapdata = new HashMap();
                        mapdata.put("index", i + 1);
                        mapdata.put("zfMoney", list.get(i).getPayMoney());
                        mapdata.put("sppPersent", list.get(i).getSppPersent());
                        mapdata.put("milepostName", list.get(i).getMilepostName());
                        mapdata.put("createDate", list.get(i).getCreateDate());
                        datalist.add(mapdata);
                    }
                    fileName = project005.getProjectName() + "项目未回款金额" + DateUtil.getCurrentDateNoSpliter();
                    map.put("records", datalist);
                    map.put("projectName", project005.getProjectName());
                    ptid = "206";
                    break;
                default:
                    break;
            }
            File formExcel = createFormExcel(ptid, fileName, map);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);

            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
        return result;
    }

    /**
     * @param model
     * @Author:zhaoyongke
     * @Description:检测项目统计
     * @Date:15:12 2021/5/10
     */
    @GetMapping("jcProTjIndex")
    @RequiresPermissions("zn:jc:ywxm:jc")
    public String jcProTjIndex(Model model) {
        // 项目归属
        List<BaseCompanyOwner> AlstCompany = baseCompanyOwnerService.selectAll();
        model.addAttribute("com", AlstCompany);
        //项目类型
        List<BaseDict> projectTypeList = DictUtil.getDictByType(DictTypes.PROJECT_TYPEJC);
        SysUserDTO user = new SysUserDTO();
        user.setUserRole("jcgw");
        List<SysUser> AlstUsers = userService.getUserDicts(user);
        model.addAttribute("userJc", AlstUsers);
        model.addAttribute("projectTypeList", projectTypeList);
        //行业
        List<BaseDict> AlstHyType = DictUtil.getDictByType(DictTypes.INDUSTRY);
        model.addAttribute("HyTypelist", AlstHyType);
        // 投资额区间
        List<BaseDict> tzelist = DictUtil.getDictByType(DictTypes.STZE001);
        model.addAttribute("tzelist", tzelist);

        // 项目进度q区间
        List<BaseDict> jdlist = DictUtil.getDictByType(DictTypes.SPJD001);
        model.addAttribute("jdlist", jdlist);
        //监理服务费
        List<BaseDict> JLFWFlist = DictUtil.getDictByType(DictTypes.JLFWF001);
        model.addAttribute("jlfwf", JLFWFlist);
        // 省
        List<SysRegion> provincelist = sysRegionService.selectListByLevelId("1");
        model.addAttribute("provincelist", provincelist);

        return "/decision/buProjectInfo/jcProTj";
    }


    /**
     * @param dto
     * @param model
     * @param page
     * @param limit
     * @Author:zhaoyongke
     * @Description: 监理统计
     * @Date:13:35 2021/5/11
     */
    @ApiOperation(value = "/showProjectJcTjList", httpMethod = "GET", notes = "展示监理统计信息")
    @GetMapping(value = "/showProjectJcTjList")
    @ResponseBody
    public ReType showProjectJcTjList(JcProjectDTO dto, Model model, String page, String limit) {
        Subject subject = SecurityUtils.getSubject();
        String tjType = dto.getTjType();
        if("day".equals(tjType)){

        }else if("week".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("~");
                dto.setStartWjDate(split[0]);
                dto.setEndWjDate(split[1]);
            }
        }else if("month".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(startdate+"-01");
                dto.setEndWjDate(startdate+"-31");
            }
        }else if("quarter".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String[] split = dto.getStartWjDate().split("-");
                String year=split[0];
                String jd=split[1];
                if("1".equals(jd)){
                    dto.setStartWjDate(year+"-01-01");
                    dto.setEndWjDate(year+"-03-31");
                }else if("2".equals(jd)){
                    dto.setStartWjDate(year+"-04-01");
                    dto.setEndWjDate(year+"-06-30");
                }else if("3".equals(jd)){
                    dto.setStartWjDate(year+"-07-01");
                    dto.setEndWjDate(year+"-09-30");
                }else if("4".equals(jd)){
                    dto.setStartWjDate(year+"-10-01");
                    dto.setEndWjDate(year+"-12-31");
                }
            }
        }else if("year".equals(tjType)){
            if(StringUtil.isNotBlank(dto.getStartWjDate())){
                String startdate=dto.getStartWjDate();
                dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                dto.setEndWjDate(startdate+"-12-31");
            }
        }

        System.out.println(dto.getStartWjDate()+"开始时间========================");
        System.out.println(dto.getEndWjDate()+"结束时间========================");
        // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
        // 分公司总经理  看到自己公司的
        // 分公司工程部经理  只能看到自己的
        // 分公司检测部门经理 只能看到自己的
        // 检测部门经理   总部的
        if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl")  || subject.hasRole("fgsdeptcheckpersonjc") || subject.hasRole("deptcheckpersonjc")  ){
            // 分公司总经理  看到自己公司的
            SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
            // 公司Id
            String companyName = sysUser.getCompanyName();
            if(StringUtils.isBlank(companyName)){
                // 如果所所属公司为空  就不能显示出来信息
                dto.setUserId("5555");
            }else{
                dto.setProjectOwner(companyName);
            }
        }
        //已经结束状态
        ReType re = new ReType();
        dto.setDestatus("000");
        String tzMoney = dto.getTzMoney();
        dto.setField(humpToUnderline(dto.getField()));
        //处理投资额区间
        if (StringUtil.isNotBlank(tzMoney)) {
            String[] tzMoneystr = tzMoney.split(",");
            if (tzMoneystr.length == 2) {
                String minTzMoney = tzMoneystr[0];
                String maxTzMoney = tzMoneystr[1];
                dto.setMinTzMoney(minTzMoney);
                dto.setMaxTzMoney(maxTzMoney);
            }
        }
        //处理监理服务费区间
        // 汇款及时性
        // 是否延期
        String isYq = dto.getIsYq();
        Page<JcProjectDTO> tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit));
        List<JcProjectDTO> data = jcProjectService.selectJcTjProject(dto);
        for (JcProjectDTO dtos :
                data) {
            String str = "";
            String[] strs = dtos.getJcAdviser().split(",");
            for (int x = 0; x < strs.length; x++) {
                SysUser user = sysUserMapper.selectByPrimaryKey(strs[x]);

                if (x == strs.length - 1) {
                    if(user!=null){
                        str = str + user.getRealName();
                    }

                } else {
                    if(user!=null){
                        str = str + user.getRealName() + ",";
                    }

                }
            }
            dtos.setJcAdviserName(str);
        }
        return new ReType(tPage.getTotal(), data);
    }

    /**
     * 监理项目统计预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableJlxm")
    public JsonUtil viewTableJlxm(SupervisorProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "监理项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();

            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }

            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl")   ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }

            List<SupervisorProjectDTO> data = supervisorProjectService.selectSupervisorJlTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //                    是否延期
                    if ("005".equals(data.get(i).getStatus())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getTzMoney())){
                         tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getHtMoney())){
                         ht = new BigDecimal(data.get(i).getHtMoney());
                    }

                    if(tz.compareTo(new BigDecimal("0"))!=0){
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                        data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setQfbl("");
                    }
                    //未开发票金额
                    BigDecimal ykfpje = new BigDecimal(data.get(i).getYkfpje());
                    BigDecimal zero = new BigDecimal("0");
                    int wk = (ht.subtract(ykfpje)).compareTo(zero);
                    if (wk < 0) {
                        data.get(i).setWkfpje("0");
                    } else {
                        data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                    }
                    BigDecimal yhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYhkje())){
                         yhkje = new BigDecimal(data.get(i).getYhkje());
                    }


                    //待回款金额
                    data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                    BigDecimal dhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getDhkje())){
                         dhkje = new BigDecimal(data.get(i).getDhkje());
                    }

                    //待回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setDhkbl("");
                    }
                    //已回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setYhkbl("");
                    }
                    //待回款比例
                   // data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    //已回款比例
                   // data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");


//                    投资额
                    data.get(i).setTzMoney(data.get(i).getTzMoney() );
//                    监理合同额
                    data.get(i).setHtMoney(data.get(i).getHtMoney() );

//                    回款及时性
                    if (StringUtil.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            HashMap map1 = new HashMap();
            map1.put("lists", data);
            map1.put("name", "监理项目统计");
            File formExcel = createFormExcel("89001", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * @param dto
     * @param response
     * @Description:监理项目统计导出excel
     * @Date:13:24 2021-10-11
     */
    @RequestMapping("exportTableJl")
    public void exportTableJl(SupervisorProjectDTO dto, HttpServletResponse response) {
        try {
            HashMap map = new HashMap<>();
            String fileName = "监理项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();
            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }
            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl")   ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }

            List<SupervisorProjectDTO> data = supervisorProjectService.selectSupervisorJlTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //                    是否延期
                    if ("005".equals(data.get(i).getStatus())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getTzMoney())){
                         tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getHtMoney())){
                        ht = new BigDecimal(data.get(i).getHtMoney());
                    }
                    if(tz.compareTo(new BigDecimal("0"))!=0){
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                        data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setQfbl("");
                    }
                    //未开发票金额
                    BigDecimal ykfpje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYkfpje())){
                        ykfpje= new BigDecimal(data.get(i).getYkfpje());
                    }

                    BigDecimal zero = new BigDecimal("0");
                    int wk = (ht.subtract(ykfpje)).compareTo(zero);
                    if (wk < 0) {
                        data.get(i).setWkfpje("0");
                    } else {
                        data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                    }
                    BigDecimal yhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYhkje())){
                         yhkje = new BigDecimal(data.get(i).getYhkje());
                    }
                    //待回款金额
                    data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                    BigDecimal dhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getDhkje())){
                         dhkje = new BigDecimal(data.get(i).getDhkje());
                    }

                    //待回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setDhkbl("");
                    }
                    //已回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setYhkbl("");
                    }
//                    //待回款比例
//                    data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
//                    //已回款比例
//                    data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");


                    //                    投资额
                    data.get(i).setTzMoney(data.get(i).getTzMoney());
                    //                    监理合同额
                    data.get(i).setHtMoney(data.get(i).getHtMoney());


                    //                    回款及时性
                    if (StringUtil.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            map.put("name", "监理项目统计");
            map.put("lists", data);
            ExcelExportUtil.exportExcel(response, map, fileName, "89001");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 咨询项目统计预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableZxxm")
    public JsonUtil viewTableZxxm(ZxProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "咨询项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();
            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }

            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl") ||  subject.hasRole("fgsdeptcheckpersonzx") ||  subject.hasRole("deptcheckpersonzx")   ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }
            List<ZxProjectDTO> data = zxProjectService.selectZxJlTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getTzMoney())){
                        System.out.println(data.get(i).getTzMoney()+"透支咔咔咔咔咔咔扩扩扩扩扩扩扩扩扩扩扩扩扩扩扩扩扩");
                         tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getHtMoney())){
                         ht = new BigDecimal(data.get(i).getHtMoney());
                    }
                    if(tz.compareTo(new BigDecimal("0"))!=0){
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                        data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setQfbl("");
                    }
                    BigDecimal ykfpje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYkfpje())){
                        //未开发票金额
                         ykfpje = new BigDecimal(data.get(i).getYkfpje());
                    }

                    BigDecimal zero = new BigDecimal("0");
                    int wk = (ht.subtract(ykfpje)).compareTo(zero);
                    if (wk < 0) {
                        data.get(i).setWkfpje("0");
                    } else {
                        data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                    }
                    BigDecimal yhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYhkje())){
                        yhkje = new BigDecimal(data.get(i).getYhkje());
                    }
                    //待回款金额
                    data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                    BigDecimal dhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getDhkje())){
                         dhkje = new BigDecimal(data.get(i).getDhkje());
                    }

                    //待回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setDhkbl("");
                    }
                    //已回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setYhkbl("");
                    }
//                    投资额
                    data.get(i).setTzMoney(data.get(i).getTzMoney() );
//                    监理合同额
                    data.get(i).setHtMoney(data.get(i).getHtMoney() );

//                    是否延期
                    if ("005".equals(data.get(i).getIsYq())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
//                    回款及时性
                    if (StringUtil.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            HashMap map1 = new HashMap();
            map1.put("lists", data);
            map1.put("name", "咨询项目统计");
            File formExcel = createFormExcel("89002", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * @param dto
     * @param response
     * @Description:咨询项目统计导出excel
     * @Date:13:24 2021-10-11
     */
    @RequestMapping("exportTableZx")
    public void exportTableZx(ZxProjectDTO dto, HttpServletResponse response) {
        try {
            HashMap map = new HashMap<>();
            String fileName = "咨询项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();
            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }
            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl") ||  subject.hasRole("fgsdeptcheckpersonzx") ||  subject.hasRole("deptcheckpersonzx")    ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }
            List<ZxProjectDTO> data = zxProjectService.selectZxJlTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getTzMoney())){
                         tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getHtMoney())){
                         ht = new BigDecimal(data.get(i).getHtMoney());
                    }
                    //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                    if(tz.compareTo(new BigDecimal("0"))!=0){
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                        data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setQfbl("");
                    }
                    //未开发票金额
                    BigDecimal ykfpje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYkfpje())){
                         ykfpje = new BigDecimal(data.get(i).getYkfpje());
                    }

                    BigDecimal zero = new BigDecimal("0");
                    int wk = (ht.subtract(ykfpje)).compareTo(zero);
                    if (wk < 0) {
                        data.get(i).setWkfpje("0");
                    } else {
                        data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                    }
                    BigDecimal yhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYhkje())) {
                        yhkje = new BigDecimal(data.get(i).getYhkje());
                    }
                    //待回款金额
                    data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                    BigDecimal dhkje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getDhkje())){
                         dhkje = new BigDecimal(data.get(i).getDhkje());
                    }

                    //待回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setDhkbl("");
                    }
                    //已回款比例
                    if(ht.compareTo(new BigDecimal("0"))!=0){
                        data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }else{
                        data.get(i).setYhkbl("");
                    }


                    //                    投资额
                    data.get(i).setTzMoney(data.get(i).getTzMoney() );
                    //                    监理合同额
                    data.get(i).setHtMoney(data.get(i).getHtMoney() );

                    //                    是否延期
                    if ("005".equals(data.get(i).getIsYq())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
                    //                    回款及时性
                    if (StringUtil.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            map.put("name", "咨询项目统计");
            map.put("lists", data);
            ExcelExportUtil.exportExcel(response, map, fileName, "89002");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 检测项目统计预览excel
     *
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping("viewTableJcxm")
    public JsonUtil viewTableJcxm(JcProjectDTO dto, HttpServletRequest request, HttpServletResponse response) {
        JsonUtil result = new JsonUtil();
        try {
            String fileName = "检测项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();
            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }
            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            // 分公司检测部门经理 只能看到自己的
            // 检测部门经理   总部的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl") || subject.hasRole("fgsdeptcheckpersonjc") || subject.hasRole("deptcheckpersonjc")    ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }
            List<JcProjectDTO> data = jcProjectService.selectJcTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtil.isNotBlank(data.get(i).getTzMoney())) {
                        tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    System.out.println("9999999987454545454545");
                    System.out.println(data.get(i).getHtMoney()+"ceshi898989888");
                    if (StringUtils.isNotBlank(data.get(i).getHtMoney())) {
                        ht = new BigDecimal(data.get(i).getHtMoney());
                        System.out.println("888888KKKKKKKKKKK");
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                        if(tz.compareTo(new BigDecimal("0"))!=0){
                            //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                            data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setQfbl("");
                        }
                        BigDecimal yhkje = new BigDecimal("0");
                        if(StringUtils.isNotBlank(data.get(i).getYhkje())){
                             yhkje = new BigDecimal(data.get(i).getYhkje());
                        }
                        //待回款金额
                        data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                        BigDecimal dhkje = new BigDecimal("0");
                        if(StringUtils.isNotBlank(data.get(i).getDhkje())){
                             dhkje = new BigDecimal(data.get(i).getDhkje());
                        }

                        //待回款比例
                        if(ht.compareTo(new BigDecimal("0"))!=0){
                            data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setDhkbl("");
                        }
                        //已回款比例
                        if(ht.compareTo(new BigDecimal("0"))!=0){
                            data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setYhkbl("");
                        }
                        //待回款比例
                       // data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        //已回款比例
                       // data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }
                    //未开发票金额
                    BigDecimal ykfpje = new BigDecimal("0");
                    if(StringUtils.isNotBlank(data.get(i).getYkfpje())) {
                        ykfpje = new BigDecimal(data.get(i).getYkfpje());
                    }
                    BigDecimal zero = new BigDecimal("0");
                    int wk = (ht.subtract(ykfpje)).compareTo(zero);
                    if (wk < 0) {
                        data.get(i).setWkfpje("0");
                    } else {
                        data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                    }



//                    投资额
                    data.get(i).setTzMoney(tz.toString());
//                    检测合同额
                    data.get(i).setHtMoney(ht.toString() );

//                    是否延期
                    if ("005".equals(data.get(i).getIsYq())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
//                    回款及时性
                    if (StringUtils.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            HashMap map1 = new HashMap();
            map1.put("lists", data);
            map1.put("name", "检测项目统计");
            File formExcel = createFormExcel("89003", fileName, map1);
            String tempFilePath = uploadUtil.getTempPath() + File.separator + new Date().getTime()
                    + File.separator + fileName + formExcel.getName().substring(formExcel.getName().lastIndexOf("."));
            File tempFile = new File(tempFilePath);
            if (!tempFile.getParentFile().exists()) {
                tempFile.getParentFile().mkdirs();
            }
            tempFile.createNewFile();
            FileUtils.copyFile(formExcel, tempFile);
            formExcel.delete();
            SupervisorFileTemp temp = new SupervisorFileTemp();
            temp.setUrl(tempFile.getPath());
            temp.setFileName(tempFile.getName());
            temp.setFileType(tempFile.getName().substring(tempFile.getName().lastIndexOf(".")));
            temp.setType("tz");
            tempService.insertSelective(temp);
            result.setFlag(true);
            result.setData(temp.getId());
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * @param dto
     * @param response
     * @Description:检测项目统计导出excel
     * @Date:13:24 2021-10-11
     */
    @RequestMapping("exportTableJc")
    public void exportTableJc(JcProjectDTO dto, HttpServletResponse response) {
        try {
            HashMap map = new HashMap<>();
            String fileName = "检测项目统计_" + DateUtil.getCurrentDateNoSpliter();
            //已经结束状态
            ReType re = new ReType();
            String tjType = dto.getTjType();
            if("day".equals(tjType)){

            }else if("week".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("~");
                    dto.setStartWjDate(split[0]);
                    dto.setEndWjDate(split[1]);
                }
            }else if("month".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(startdate+"-01");
                    dto.setEndWjDate(startdate+"-31");
                }
            }else if("quarter".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String[] split = dto.getStartWjDate().split("-");
                    String year=split[0];
                    String jd=split[1];
                    if("1".equals(jd)){
                        dto.setStartWjDate(year+"-01-01");
                        dto.setEndWjDate(year+"-03-31");
                    }else if("2".equals(jd)){
                        dto.setStartWjDate(year+"-04-01");
                        dto.setEndWjDate(year+"-06-30");
                    }else if("3".equals(jd)){
                        dto.setStartWjDate(year+"-07-01");
                        dto.setEndWjDate(year+"-09-30");
                    }else if("4".equals(jd)){
                        dto.setStartWjDate(year+"-10-01");
                        dto.setEndWjDate(year+"-12-31");
                    }
                }
            }else if("year".equals(tjType)){
                if(StringUtil.isNotBlank(dto.getStartWjDate())){
                    String startdate=dto.getStartWjDate();
                    dto.setStartWjDate(Integer.valueOf(startdate)-1+"-12-31");
                    dto.setEndWjDate(startdate+"-12-31");
                }
            }

            System.out.println(dto.getStartWjDate()+"开始时间========================");
            System.out.println(dto.getEndWjDate()+"结束时间========================");
            dto.setDestatus("000");
            String tzMoney = dto.getTzMoney();
            //处理投资额区间
            if (StringUtil.isNotBlank(tzMoney)) {
                String[] tzMoneystr = tzMoney.split(",");
                if (tzMoneystr.length == 2) {
                    String minTzMoney = tzMoneystr[0];
                    String maxTzMoney = tzMoneystr[1];
                    dto.setMinTzMoney(minTzMoney);
                    dto.setMaxTzMoney(maxTzMoney);
                }
            }
            Subject subject = SecurityUtils.getSubject();
            // 正中总部的工程部经理可以查看正中总部的所有监理项目  分公司看到分公司的
            // 分公司总经理  看到自己公司的
            // 分公司工程部经理  只能看到自己的
            // 分公司检测部门经理 只能看到自己的
            // 检测部门经理   总部的
            if(subject.hasRole("fgszjl")  || subject.hasRole("gcbjl")  || subject.hasRole("fgsgcbjl")  || subject.hasRole("fgsdeptcheckpersonjc") || subject.hasRole("deptcheckpersonjc") ){
                // 分公司总经理  看到自己公司的
                SysUser sysUser = sysUserService.selectByPrimaryKey(CommonUtil.getUserId());
                // 公司Id
                String companyName = sysUser.getCompanyName();
                if(StringUtils.isBlank(companyName)){
                    // 如果所所属公司为空  就不能显示出来信息
                    dto.setUserId("5555");
                }else{
                    dto.setProjectOwner(companyName);
                }
            }
            List<JcProjectDTO> data = jcProjectService.selectJcTjProject(dto);
            if (data != null && data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    //处理项目状态
                    if (StringUtil.isNotBlank(data.get(i).getStatus())) {
                        if ("000".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已删除");
                        } else if ("001".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未提交");
                        } else if ("002".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("未启动");
                        } else if ("003".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("进行中");
                        } else if ("004".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已完成");
                        } else if ("005".equals(data.get(i).getStatus())) {
                            data.get(i).setStatus("已延期");
                        }
                    }
                    //年份
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                    data.get(i).setYear(sdf.format(data.get(i).getCreateDate()));
                    //项目进度
                    data.get(i).setProgress(data.get(i).getProgress() + "%");

                    DecimalFormat df = new DecimalFormat("#.00");
                    BigDecimal bai = new BigDecimal("100");
                    //取费比例
                    BigDecimal tz = new BigDecimal("0");
                    if(StringUtil.isNotBlank(data.get(i).getTzMoney())){
                        tz = new BigDecimal(data.get(i).getTzMoney());
                    }
                    BigDecimal ht = new BigDecimal("0");
                    if(StringUtil.isNotBlank(data.get(i).getHtMoney())){
                        ht = new BigDecimal(data.get(i).getHtMoney());
                        //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号

                        if(tz.compareTo(new BigDecimal("0"))!=0){
                            //合同额除投资额保留八位小数 乘一百保留两位小数加上百分号
                            data.get(i).setQfbl((((ht.divide(tz, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setQfbl("");
                        }
                        //未开发票金额
                        BigDecimal ykfpje = new BigDecimal("0");
                        if(StringUtil.isNotBlank(data.get(i).getYkfpje())){
                            ykfpje = new BigDecimal(data.get(i).getYkfpje());
                        }
                        BigDecimal zero = new BigDecimal("0");
                        int wk = (ht.subtract(ykfpje)).compareTo(zero);
                        if (wk < 0) {
                            data.get(i).setWkfpje("0");
                        } else {
                            data.get(i).setWkfpje(ht.subtract(ykfpje).toString());
                        }

                        BigDecimal yhkje = new BigDecimal("0");
                        if(StringUtil.isNotBlank(data.get(i).getYhkje())) {
                            yhkje = new BigDecimal(data.get(i).getYhkje());
                        }
                        //待回款金额
                        data.get(i).setDhkje((ht.subtract(yhkje)).toString());
                        BigDecimal dhkje = new BigDecimal("0");
                        if(StringUtil.isNotBlank(data.get(i).getDhkje())){
                            dhkje = new BigDecimal(data.get(i).getDhkje());
                        }

                        //待回款比例
                        if(ht.compareTo(new BigDecimal("0"))!=0){
                            data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setDhkbl("");
                        }
                        //已回款比例
                        if(ht.compareTo(new BigDecimal("0"))!=0){
                            data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        }else{
                            data.get(i).setYhkbl("");
                        }
                        //待回款比例
                      //  data.get(i).setDhkbl((((dhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                        //已回款比例
                       // data.get(i).setYhkbl((((yhkje.divide(ht, 8, BigDecimal.ROUND_HALF_UP).multiply(bai)).setScale(2, BigDecimal.ROUND_HALF_UP)).toString()) + "%");
                    }

                    //                    投资额
                    data.get(i).setTzMoney(tz.toString());
                    //                    检测合同额
                    data.get(i).setHtMoney(ht.toString());

                    //                    是否延期
                    if ("005".equals(data.get(i).getIsYq())) {
                        data.get(i).setIsYq("是");
                    } else {
                        data.get(i).setIsYq("否");
                    }
                    //                    回款及时性
                    if (StringUtil.isNotBlank(data.get(i).getHkjsx())) {
                        if ("001".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("提前");
                        } else if ("002".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("按时");
                        } else if ("003".equals(data.get(i).getHkjsx())) {
                            data.get(i).setHkjsx("延期");
                        }
                    }
                }
            }
            map.put("name", "检测项目统计");
            map.put("lists", data);
            ExcelExportUtil.exportExcel(response, map, fileName, "89003");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //排序字段处理
    public static String humpToUnderline(String name) {
        StringBuilder result = new StringBuilder();
        if (name != null && name.length() > 0) {
            // 将第一个字符处理成大写
            result.append(name.substring(0, 1).toUpperCase());
            // 循环处理其余字符
            for (int i = 1; i < name.length(); i++) {
                String s = name.substring(i, i + 1);
                // 在大写字母前添加下划线
                if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
                    result.append("_");
                }
                // 其他字符直接转成大写
                result.append(s.toUpperCase());
            }
        }
        return result.toString();
    }
}
